]> WPIA git - gigi.git/blob - src/org/cacert/gigi/dbObjects/Name.java
UPD: minor consistency cleanups
[gigi.git] / src / org / cacert / gigi / dbObjects / Name.java
1 package org.cacert.gigi.dbObjects;
2
3 import java.io.PrintWriter;
4 import java.util.Map;
5
6 import org.cacert.gigi.dbObjects.wrappers.DataContainer;
7 import org.cacert.gigi.localisation.Language;
8 import org.cacert.gigi.output.template.Outputable;
9 import org.cacert.gigi.util.HTMLEncoder;
10
11 @DataContainer
12 public class Name implements Outputable {
13
14     private final String fname;
15
16     private final String mname;
17
18     private final String lname;
19
20     private final String suffix;
21
22     public Name(String fname, String lname, String mname, String suffix) {
23         this.fname = fname;
24         this.lname = lname;
25         this.mname = mname;
26         this.suffix = suffix;
27     }
28
29     @Override
30     public void output(PrintWriter out, Language l, Map<String, Object> vars) {
31         out.println("<span class=\"accountdetail\">");
32         out.print("<span class=\"fname\">");
33         out.print(HTMLEncoder.encodeHTML(fname));
34         out.print("</span> ");
35         out.print("<span class=\"lname\">");
36         out.print(HTMLEncoder.encodeHTML(lname));
37         out.print("</span>");
38         out.println("</span>");
39     }
40
41     @Override
42     public String toString() {
43         return fname + " " + lname;
44     }
45
46     @Override
47     public int hashCode() {
48         final int prime = 31;
49         int result = 1;
50         result = prime * result + ((fname == null) ? 0 : fname.hashCode());
51         result = prime * result + ((lname == null) ? 0 : lname.hashCode());
52         result = prime * result + ((mname == null) ? 0 : mname.hashCode());
53         result = prime * result + ((suffix == null) ? 0 : suffix.hashCode());
54         return result;
55     }
56
57     @Override
58     public boolean equals(Object obj) {
59         if (this == obj) {
60             return true;
61         }
62         if (obj == null) {
63             return false;
64         }
65         if (getClass() != obj.getClass()) {
66             return false;
67         }
68         Name other = (Name) obj;
69         if (fname == null) {
70             if (other.fname != null) {
71                 return false;
72             }
73         } else if ( !fname.equals(other.fname)) {
74             return false;
75         }
76         if (lname == null) {
77             if (other.lname != null) {
78                 return false;
79             }
80         } else if ( !lname.equals(other.lname)) {
81             return false;
82         }
83         if (mname == null) {
84             if (other.mname != null) {
85                 return false;
86             }
87         } else if ( !mname.equals(other.mname)) {
88             return false;
89         }
90         if (suffix == null) {
91             if (other.suffix != null) {
92                 return false;
93             }
94         } else if ( !suffix.equals(other.suffix)) {
95             return false;
96         }
97         return true;
98     }
99
100     public boolean matches(String text) {
101         return text.equals(fname + " " + lname) || //
102                 (mname != null && text.equals(fname + " " + mname + " " + lname)) || //
103                 (suffix != null && text.equals(fname + " " + lname + " " + suffix)) || //
104                 (mname != null && suffix != null && text.equals(fname + " " + mname + " " + lname + " " + suffix));
105     }
106
107     public String getFname() {
108         return fname;
109     }
110
111     public String getLname() {
112         return lname;
113     }
114
115     public String getMname() {
116         return mname;
117     }
118
119     public String getSuffix() {
120         return suffix;
121     }
122
123 }