]> WPIA git - gigi.git/blob - src/club/wpia/gigi/dbObjects/NamePart.java
fix: ResultSet.getDate is often wrong as it fetches day-precision times
[gigi.git] / src / club / wpia / gigi / dbObjects / NamePart.java
1 package club.wpia.gigi.dbObjects;
2
3 import club.wpia.gigi.database.DBEnum;
4 import club.wpia.gigi.database.GigiResultSet;
5 import club.wpia.gigi.dbObjects.wrappers.DataContainer;
6
7 @DataContainer
8 public class NamePart {
9
10     public enum NamePartType implements DBEnum {
11         FIRST_NAME, LAST_NAME, SINGLE_NAME, SUFFIX;
12
13         public String getDBName() {
14             return name().toLowerCase().replace("_", "-");
15         }
16     }
17
18     private NamePartType type;
19
20     private String value;
21
22     public NamePart(NamePartType type, String value) {
23         if (type == null || value == null || value.trim().isEmpty() || !value.trim().equals(value)) {
24             throw new IllegalArgumentException();
25         }
26         this.type = type;
27         this.value = value;
28     }
29
30     public NamePart(GigiResultSet rs1) {
31         value = rs1.getString("value");
32         type = NamePartType.valueOf(rs1.getString("type").replace("-", "_").toUpperCase());
33     }
34
35     public NamePartType getType() {
36         return type;
37     }
38
39     public String getValue() {
40         return value;
41     }
42
43     @Override
44     public String toString() {
45         return value;
46     }
47
48     @Override
49     public int hashCode() {
50         final int prime = 31;
51         int result = 1;
52         result = prime * result + ((type == null) ? 0 : type.hashCode());
53         result = prime * result + ((value == null) ? 0 : value.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         NamePart other = (NamePart) obj;
69         if (type != other.type) {
70             return false;
71         }
72         if (value == null) {
73             if (other.value != null) {
74                 return false;
75             }
76         } else if ( !value.equals(other.value)) {
77             return false;
78         }
79         return true;
80     }
81
82 }