1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package net.sourceforge.plantumldependency.cli.main.option.programminglanguage.argument.java;
26
27 import static java.util.logging.Level.SEVERE;
28 import static java.util.logging.Logger.getLogger;
29 import static net.sourceforge.plantumldependency.cli.generic.type.impl.DependencyTypeImpl.generateDependencyFullName;
30 import static net.sourceforge.plantumldependency.common.constants.log.ErrorConstants.UNEXPECTED_ERROR;
31 import static net.sourceforge.plantumldependency.common.utils.comparable.ComparableResult.EQUAL;
32
33 import java.io.Serializable;
34 import java.util.Set;
35 import java.util.TreeSet;
36 import java.util.logging.Logger;
37
38 import net.sourceforge.plantumldependency.cli.main.option.programminglanguage.argument.java.type.JavaType;
39 import net.sourceforge.plantumldependency.common.clone.DeepCloneable;
40
41
42
43
44
45
46
47
48
49 public class JavaRawDependency implements Comparable < JavaRawDependency >, Serializable,
50 DeepCloneable < JavaRawDependency > {
51
52
53 private static final long serialVersionUID = -8047630217535429852L;
54
55
56 private static final transient Logger LOGGER = getLogger(JavaRawDependency.class.getName());
57
58
59 private boolean isAbstract;
60
61
62 private String packageName;
63
64
65 private JavaType type;
66
67
68 private String name;
69
70
71 private boolean nativeMethods;
72
73
74
75
76
77 private Set < String > parentExtensions;
78
79
80
81
82
83 private Set < String > parentImplementations;
84
85
86
87
88
89
90 public JavaRawDependency() {
91 super();
92 }
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115 public JavaRawDependency(final boolean isAbs, final String dependencyPackageName, final JavaType javaType,
116 final String dependencyName, final Set < String > extensions, final Set < String > implementations,
117 final boolean nativeMth) {
118 setAbstract(isAbs);
119 setPackageName(dependencyPackageName);
120 setType(javaType);
121 setName(dependencyName);
122 setParentExtensions(extensions);
123 setParentImplementations(implementations);
124 setNativeMethods(nativeMth);
125 }
126
127
128
129
130
131
132 @Override
133 public int compareTo(final JavaRawDependency j) {
134 int comparison = EQUAL.getResult();
135 if (this != j) {
136 comparison = packageName.compareTo(j.packageName);
137 if (comparison == EQUAL.getResult()) {
138 comparison = name.compareTo(j.name);
139 }
140 }
141 return comparison;
142 }
143
144
145
146
147
148
149 @Override
150 public JavaRawDependency deepClone() {
151 JavaRawDependency j = null;
152
153 try {
154 j = (JavaRawDependency) super.clone();
155 j.parentExtensions = new TreeSet < String >(getParentExtensions());
156 j.parentImplementations = new TreeSet < String >(getParentImplementations());
157 } catch (final CloneNotSupportedException cnse) {
158 LOGGER.log(SEVERE, UNEXPECTED_ERROR, cnse);
159 }
160
161 return j;
162 }
163
164
165
166
167
168
169 @Override
170 public boolean equals(final Object obj) {
171 if (this == obj) {
172 return true;
173 }
174 if (obj == null) {
175 return false;
176 }
177 if (getClass() != obj.getClass()) {
178 return false;
179 }
180 final JavaRawDependency other = (JavaRawDependency) obj;
181 if (name == null) {
182 if (other.name != null) {
183 return false;
184 }
185 } else if (!name.equals(other.name)) {
186 return false;
187 }
188 if (packageName == null) {
189 if (other.packageName != null) {
190 return false;
191 }
192 } else if (!packageName.equals(other.packageName)) {
193 return false;
194 }
195 return true;
196 }
197
198
199
200
201
202
203
204 public String getFullName() {
205 return generateDependencyFullName(getPackageName(), getName());
206 }
207
208
209
210
211
212
213
214
215 public String getName() {
216 return name;
217 }
218
219
220
221
222
223
224
225
226 public String getPackageName() {
227 return packageName;
228 }
229
230
231
232
233
234
235
236
237 public Set < String > getParentExtensions() {
238 return parentExtensions;
239 }
240
241
242
243
244
245
246
247
248 public Set < String > getParentImplementations() {
249 return parentImplementations;
250 }
251
252
253
254
255
256
257
258
259 public JavaType getType() {
260 return type;
261 }
262
263
264
265
266
267
268 @Override
269 public int hashCode() {
270 final int prime = 31;
271 int result = 1;
272 result = prime * result + ((name == null) ? 0 : name.hashCode());
273 result = prime * result + ((packageName == null) ? 0 : packageName.hashCode());
274 return result;
275 }
276
277
278
279
280
281
282
283
284 public boolean hasNativeMethods() {
285 return nativeMethods;
286 }
287
288
289
290
291
292
293
294
295 public boolean isAbstract() {
296 return isAbstract;
297 }
298
299
300
301
302
303
304
305
306
307 public void setAbstract(final boolean value) {
308 isAbstract = value;
309 }
310
311
312
313
314
315
316
317
318
319 public void setName(final String value) {
320 name = value;
321 }
322
323
324
325
326
327
328
329
330
331 public void setNativeMethods(final boolean value) {
332 nativeMethods = value;
333 }
334
335
336
337
338
339
340
341
342
343 public void setPackageName(final String value) {
344 packageName = value;
345 }
346
347
348
349
350
351
352
353
354
355 public void setParentExtensions(final Set < String > value) {
356 parentExtensions = value;
357 }
358
359
360
361
362
363
364
365
366
367 public void setParentImplementations(final Set < String > value) {
368 parentImplementations = value;
369 }
370
371
372
373
374
375
376
377
378
379 public void setType(final JavaType value) {
380 type = value;
381 }
382
383
384
385
386
387
388 @Override
389 public String toString() {
390 return getClass().getSimpleName() + " [isAbstract=" + isAbstract + ", packageName=" + packageName + ", type="
391 + type + ", name=" + name + ", nativeMethods=" + nativeMethods + ", parentExtensions="
392 + parentExtensions + ", parentImplementations=" + parentImplementations + "]";
393 }
394 }