001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.cmp2.commerce;
023:
024: public class FormalName implements java.io.Serializable {
025: static final long serialVersionUID = -7922312634732090491L;
026: private String first;
027: private char mi;
028: private String last;
029:
030: public FormalName() {
031: }
032:
033: public FormalName(String first, char mi, String last) {
034: setFirst(first);
035: setMi(mi);
036: setLast(last);
037: }
038:
039: public String getFirst() {
040: return first;
041: }
042:
043: public void setFirst(String first) {
044: if (first == null) {
045: throw new IllegalArgumentException("First is null");
046: }
047: first = first.trim();
048: if (first.length() == 0) {
049: throw new IllegalArgumentException("First is zero length");
050: }
051: this .first = first;
052: }
053:
054: public char getMi() {
055: return mi;
056: }
057:
058: public void setMi(char mi) {
059: this .mi = mi;
060: }
061:
062: public String getLast() {
063: return last;
064: }
065:
066: public void setLast(String last) {
067: if (last == null) {
068: throw new IllegalArgumentException("Last is null");
069: }
070: last = last.trim();
071: if (last.length() == 0) {
072: throw new IllegalArgumentException("Last is zero length");
073: }
074: this .last = last;
075: }
076:
077: public boolean equals(Object obj) {
078: if (obj instanceof FormalName) {
079: FormalName name = (FormalName) obj;
080: return equal(name.first, first) && name.mi == mi
081: && equal(name.last, last);
082: }
083: return false;
084: }
085:
086: private boolean equal(String a, String b) {
087: return (a == null && b == null) || (a != null && a.equals(b));
088: }
089:
090: public String toString() {
091: StringBuffer buf = new StringBuffer();
092: if (first != null) {
093: buf.append(first);
094: }
095: if (mi != '\u0000') {
096: if (first != null) {
097: buf.append(" ");
098: }
099: buf.append(mi).append(".");
100: }
101: if (last != null) {
102: if (first != null || mi != '\u0000') {
103: buf.append(" ");
104: }
105: buf.append(last);
106: }
107: return buf.toString();
108: }
109: }
|