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