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.generic.impl;
26
27 import static java.util.logging.Level.SEVERE;
28 import static java.util.logging.Logger.getLogger;
29 import static net.sourceforge.plantumldependency.cli.constants.log.ErrorConstants.DEPENDENCY_TYPE_NULL_ERROR;
30 import static net.sourceforge.plantumldependency.common.constants.log.ErrorConstants.UNEXPECTED_ERROR;
31 import static net.sourceforge.plantumldependency.common.utils.check.ParameterCheckerUtils.checkNull;
32 import static net.sourceforge.plantumldependency.common.utils.comparable.ComparableResult.AFTER;
33 import static net.sourceforge.plantumldependency.common.utils.comparable.ComparableResult.EQUAL;
34
35 import java.util.logging.Logger;
36
37 import net.sourceforge.plantumldependency.cli.generic.GenericDependency;
38 import net.sourceforge.plantumldependency.cli.generic.type.DependencyType;
39 import net.sourceforge.plantumldependency.cli.generic.type.impl.stubimpl.StubDependencyTypeImpl;
40
41
42
43
44
45
46
47
48
49 public class GenericDependencyImpl implements GenericDependency {
50
51
52 private static final long serialVersionUID = 4512036274880797908L;
53
54
55 private static final transient Logger LOGGER = getLogger(GenericDependencyImpl.class.getName());
56
57
58 private DependencyType dependencyType;
59
60
61
62
63
64
65
66
67
68
69 public GenericDependencyImpl(final DependencyType type) {
70 checkNull(type, DEPENDENCY_TYPE_NULL_ERROR);
71
72 dependencyType = type;
73 }
74
75
76
77
78
79
80
81
82
83
84
85
86
87 public GenericDependencyImpl(final String dependencyName, final String dependencyPackageName) {
88 this(new StubDependencyTypeImpl(dependencyName, dependencyPackageName));
89 }
90
91
92
93
94
95
96 @Override
97 public int compareTo(final GenericDependency a) {
98 int comparison = AFTER.getResult();
99
100 if (this == a) {
101 comparison = EQUAL.getResult();
102 } else {
103 comparison = getDependencyType().compareTo(a.getDependencyType());
104 }
105
106 return comparison;
107 }
108
109
110
111
112
113
114 @Override
115 public GenericDependency deepClone() {
116 GenericDependencyImpl g = null;
117
118 try {
119 g = (GenericDependencyImpl) super.clone();
120 g.dependencyType = getDependencyType().deepClone();
121 } catch (final CloneNotSupportedException cnse) {
122 LOGGER.log(SEVERE, UNEXPECTED_ERROR, cnse);
123 }
124
125 return g;
126 }
127
128
129
130
131
132
133 @Override
134 public boolean equals(final Object obj) {
135 if (this == obj) {
136 return true;
137 }
138 if (obj == null) {
139 return false;
140 }
141 if (getClass() != obj.getClass()) {
142 return false;
143 }
144 final GenericDependencyImpl other = (GenericDependencyImpl) obj;
145 if (dependencyType == null) {
146 if (other.dependencyType != null) {
147 return false;
148 }
149 } else if (!dependencyType.equals(other.dependencyType)) {
150 return false;
151 }
152 return true;
153 }
154
155
156
157
158
159
160 @Override
161 public DependencyType getDependencyType() {
162 return dependencyType;
163 }
164
165
166
167
168
169
170 @Override
171 public String getFullName() {
172 return getDependencyType().getFullName();
173 }
174
175
176
177
178
179
180 @Override
181 public String getName() {
182 return getDependencyType().getName();
183 }
184
185
186
187
188
189
190 @Override
191 public String getPackageName() {
192 return getDependencyType().getPackageName();
193 }
194
195
196
197
198
199
200 @Override
201 public int hashCode() {
202 final int prime = 31;
203 int result = 1;
204 result = prime * result + ((dependencyType == null) ? 0 : dependencyType.hashCode());
205 return result;
206 }
207
208
209
210
211
212
213 @Override
214 public void setDependencyType(final DependencyType value) {
215 dependencyType = value;
216 }
217
218
219
220
221
222
223 @Override
224 public String toString() {
225 return getClass().getSimpleName() + " [dependencyType=" + dependencyType + "]";
226 }
227 }