]> WPIA git - gigi.git/blob - src/org/cacert/gigi/dbObjects/NamePart.java
fix: Avoid warning when PoJAM is disabled
[gigi.git] / src / org / cacert / gigi / dbObjects / NamePart.java
1 package org.cacert.gigi.dbObjects;
2
3 import org.cacert.gigi.database.GigiResultSet;
4 import org.cacert.gigi.dbObjects.wrappers.DataContainer;
5
6 @DataContainer
7 public class NamePart {
8
9     public enum NamePartType {
10         FIRST_NAME, LAST_NAME, SINGLE_NAME, SUFFIX;
11
12         public String getDbValue() {
13             return name().toLowerCase().replace("_", "-");
14         }
15     }
16
17     private NamePartType type;
18
19     private String value;
20
21     public NamePart(NamePartType type, String value) {
22         if (type == null || value == null || value.trim().isEmpty() || !value.trim().equals(value)) {
23             throw new IllegalArgumentException();
24         }
25         this.type = type;
26         this.value = value;
27     }
28
29     public NamePart(GigiResultSet rs1) {
30         value = rs1.getString("value");
31         type = NamePartType.valueOf(rs1.getString("type").replace("-", "_").toUpperCase());
32     }
33
34     public NamePartType getType() {
35         return type;
36     }
37
38     public String getValue() {
39         return value;
40     }
41
42     @Override
43     public String toString() {
44         return value;
45     }
46
47     @Override
48     public int hashCode() {
49         final int prime = 31;
50         int result = 1;
51         result = prime * result + ((type == null) ? 0 : type.hashCode());
52         result = prime * result + ((value == null) ? 0 : value.hashCode());
53         return result;
54     }
55
56     @Override
57     public boolean equals(Object obj) {
58         if (this == obj) {
59             return true;
60         }
61         if (obj == null) {
62             return false;
63         }
64         if (getClass() != obj.getClass()) {
65             return false;
66         }
67         NamePart other = (NamePart) obj;
68         if (type != other.type) {
69             return false;
70         }
71         if (value == null) {
72             if (other.value != null) {
73                 return false;
74             }
75         } else if ( !value.equals(other.value)) {
76             return false;
77         }
78         return true;
79     }
80
81 }