1 22 package org.jboss.test.cmp2.commerce; 23 24 25 public class FormalName implements java.io.Serializable { 26 private String first; 27 private char mi; 28 private String last; 29 30 public FormalName() { 31 } 32 33 public FormalName(String first, char mi, String last) { 34 setFirst(first); 35 setMi(mi); 36 setLast(last); 37 } 38 39 public String getFirst() { 40 return first; 41 } 42 43 public void setFirst(String first) { 44 if(first == null) { 45 throw new IllegalArgumentException ("First is null"); 46 } 47 first = first.trim(); 48 if(first.length() == 0) { 49 throw new IllegalArgumentException ("First is zero length"); 50 } 51 this.first = first; 52 } 53 54 public char getMi() { 55 return mi; 56 } 57 58 public void setMi(char mi) { 59 this.mi = mi; 60 } 61 public String getLast() { 62 return last; 63 } 64 65 public void setLast(String last) { 66 if(last == null) { 67 throw new IllegalArgumentException ("Last is null"); 68 } 69 last = last.trim(); 70 if(last.length() == 0) { 71 throw new IllegalArgumentException ("Last is zero length"); 72 } 73 this.last = last; 74 } 75 76 public boolean equals(Object obj) { 77 if(obj instanceof FormalName) { 78 FormalName name = (FormalName)obj; 79 return equal(name.first, first) && 80 name.mi==mi && 81 equal(name.last, last); 82 } 83 return false; 84 } 85 86 private boolean equal(String a, String b) { 87 return (a==null && b==null) || (a!=null && a.equals(b)); 88 } 89 90 public String toString() { 91 StringBuffer buf = new StringBuffer (); 92 if(first != null) { 93 buf.append(first); 94 } 95 if(mi != '\u0000') { 96 if(first != null) { 97 buf.append(" "); 98 } 99 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 } 110 | Popular Tags |