KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cmp2 > commerce > FormalName


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.cmp2.commerce;
23
24
25 public class FormalName implements java.io.Serializable JavaDoc {
26     private String JavaDoc first;
27     private char mi;
28     private String JavaDoc last;
29     
30     public FormalName() {
31     }
32     
33     public FormalName(String JavaDoc first, char mi, String JavaDoc last) {
34         setFirst(first);
35         setMi(mi);
36         setLast(last);
37     }
38     
39     public String JavaDoc getFirst() {
40         return first;
41     }
42     
43     public void setFirst(String JavaDoc first) {
44       if(first == null) {
45          throw new IllegalArgumentException JavaDoc("First is null");
46       }
47       first = first.trim();
48       if(first.length() == 0) {
49          throw new IllegalArgumentException JavaDoc("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 JavaDoc getLast() {
62         return last;
63     }
64     
65     public void setLast(String JavaDoc last) {
66       if(last == null) {
67          throw new IllegalArgumentException JavaDoc("Last is null");
68       }
69       last = last.trim();
70       if(last.length() == 0) {
71          throw new IllegalArgumentException JavaDoc("Last is zero length");
72       }
73         this.last = last;
74     }
75
76     public boolean equals(Object JavaDoc 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 JavaDoc a, String JavaDoc b) {
87         return (a==null && b==null) || (a!=null && a.equals(b));
88     }
89     
90     public String JavaDoc toString() {
91         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
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