1 package uk.ac.ebi.intenz.domain.enzyme;
2
3 import uk.ac.ebi.intenz.domain.constants.EnzymeNameQualifierConstant;
4 import uk.ac.ebi.intenz.domain.constants.EnzymeNameTypeConstant;
5 import uk.ac.ebi.intenz.domain.constants.EnzymeSourceConstant;
6 import uk.ac.ebi.intenz.domain.constants.EnzymeViewConstant;
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 public class EnzymeName implements Comparable<EnzymeName>, Viewable {
27
28 public static EnzymeName UNDEF = new EnzymeName("", EnzymeNameTypeConstant.UNDEF, EnzymeNameQualifierConstant.UNDEF,
29 EnzymeSourceConstant.UNDEF, EnzymeViewConstant.UNDEF);
30
31 private String name;
32
33 private EnzymeNameTypeConstant type;
34
35 private EnzymeNameQualifierConstant qualifier;
36
37 private EnzymeSourceConstant source;
38
39 private EnzymeViewConstant view;
40
41
42
43
44
45
46
47
48
49 private EnzymeName(String name, EnzymeNameTypeConstant type, EnzymeNameQualifierConstant qualifier,
50 EnzymeSourceConstant source, EnzymeViewConstant view) {
51 this.name = name;
52 this.type = type;
53 this.qualifier = qualifier;
54 this.source = source;
55 this.view = view;
56 }
57
58 public static EnzymeName valueOf(String name, EnzymeNameTypeConstant type, EnzymeNameQualifierConstant qualifier,
59 EnzymeSourceConstant source, EnzymeViewConstant view) {
60 if (type == EnzymeNameTypeConstant.COMMON_NAME) return getCommonNameInstance(name, source, view);
61 if (type == EnzymeNameTypeConstant.SYSTEMATIC_NAME) return getSystematicNameInstance(name, source, view);
62 if (type == EnzymeNameTypeConstant.OTHER_NAME) return getSynonymInstance(name, qualifier, source, view);
63 throw new IllegalArgumentException("The given type is not supported.");
64 }
65
66
67
68
69
70
71
72
73
74 public static EnzymeName getCommonNameInstance(String name, EnzymeSourceConstant source, EnzymeViewConstant view) {
75 if (name == null) throw new NullPointerException("Parameter 'name' must not be null.");
76 if (source == null) throw new NullPointerException("Parameter 'source' must not be null.");
77 if (view == null) throw new NullPointerException("Parameter 'view' must not be null.");
78 if (name.equals("")) throw new IllegalArgumentException("Parameter 'name' must not be empty.");
79
80 return new EnzymeName(name, EnzymeNameTypeConstant.COMMON_NAME,
81 EnzymeNameQualifierConstant.UNDEF, source, view);
82 }
83
84
85
86
87
88
89
90
91
92 public static EnzymeName getSystematicNameInstance(String name, EnzymeSourceConstant source, EnzymeViewConstant view) {
93 if (name == null) throw new NullPointerException("Parameter 'name' must not be null.");
94 if (source == null) throw new NullPointerException("Parameter 'source' must not be null.");
95 if (view == null) throw new NullPointerException("Parameter 'view' must not be null.");
96 if (name.equals("")) throw new IllegalArgumentException("Parameter 'name' must not be empty.");
97
98 return new EnzymeName(name, EnzymeNameTypeConstant.SYSTEMATIC_NAME,
99 EnzymeNameQualifierConstant.UNDEF, source, view);
100 }
101
102
103
104
105
106
107
108
109
110
111 public static EnzymeName getSynonymInstance(String name, EnzymeNameQualifierConstant qualifier,
112 EnzymeSourceConstant source, EnzymeViewConstant view) {
113 if (name == null) throw new NullPointerException("Parameter 'name' must not be null.");
114 if (qualifier == null) throw new NullPointerException("Parameter 'qualifier' must not be null.");
115 if (source == null) throw new NullPointerException("Parameter 'source' must not be null.");
116 if (view == null) throw new NullPointerException("Parameter 'view' must not be null.");
117 if (name.equals("")) throw new IllegalArgumentException("Parameter 'name' must not be empty.");
118
119 return new EnzymeName(name, EnzymeNameTypeConstant.OTHER_NAME, qualifier, source, view);
120 }
121
122
123
124
125
126 public int compareTo(EnzymeName name) {
127 int result = name.getSource().toString().compareTo(source.toString());
128 if (result == 0) {
129 return (name.getName().compareTo(this.name));
130 }
131 return result;
132 }
133
134
135
136
137
138
139
140 public boolean equals(Object o) {
141 if (this == o) return true;
142 if (!(o instanceof EnzymeName)) return false;
143
144 final EnzymeName enzymeName = (EnzymeName) o;
145
146 if (name != null ? !name.equals(enzymeName.name) : enzymeName.name != null) return false;
147 if (qualifier != null ? !qualifier.equals(enzymeName.qualifier) : enzymeName.qualifier != null) return false;
148 if (source != null ? !source.equals(enzymeName.source) : enzymeName.source != null) return false;
149 if (type != null ? !type.equals(enzymeName.type) : enzymeName.type != null) return false;
150 if (view != null ? !view.equals(enzymeName.view) : enzymeName.view != null) return false;
151
152 return true;
153 }
154
155
156
157
158
159
160 public int hashCode() {
161 int result;
162 result = (name != null ? name.hashCode() : 0);
163 result = 29 * result + (type != null ? type.hashCode() : 0);
164 result = 29 * result + (qualifier != null ? qualifier.hashCode() : 0);
165 result = 29 * result + (source != null ? source.hashCode() : 0);
166 result = 29 * result + (view != null ? view.hashCode() : 0);
167 return result;
168 }
169
170
171
172
173
174
175
176
177 public String getName() {
178 return name;
179 }
180
181
182
183
184
185
186
187 public EnzymeNameTypeConstant getType() {
188 return type;
189 }
190
191
192
193
194
195
196
197 public EnzymeNameQualifierConstant getQualifier() {
198 return qualifier;
199 }
200
201
202
203
204
205
206
207 public EnzymeSourceConstant getSource() {
208 return source;
209 }
210
211
212
213
214
215
216
217
218
219 public EnzymeViewConstant getView() {
220 return view;
221 }
222
223
224 }