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