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.element;
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.tag.PlantUMLClassesDiagramElementTag;
35
36
37
38
39
40
41
42
43 public abstract class AbstractPlantUMLClassesDiagramElement implements PlantUMLClassesDiagramElement {
44
45
46 private static final long serialVersionUID = -698646710338667065L;
47
48
49 private static final transient Logger LOGGER = getLogger(AbstractPlantUMLClassesDiagramElement.class.getName());
50
51
52 private final String name;
53
54
55 private final PlantUMLClassesDiagramElementTag elementTag;
56
57
58
59
60
61
62
63
64
65
66
67 protected AbstractPlantUMLClassesDiagramElement(final String fullName, final PlantUMLClassesDiagramElementTag tag) {
68 name = fullName;
69 elementTag = tag;
70 }
71
72
73
74
75
76
77 @Override
78 public int compareTo(final PlantUMLClassesDiagramElement o) {
79 int comparison;
80
81 if (this == o) {
82 comparison = EQUAL.getResult();
83 } else {
84 if (getElementTag().equals(o.getElementTag())) {
85 comparison = getName().compareTo(o.getName());
86 } else {
87 comparison = getElementTag().toString().compareTo(o.getElementTag().toString());
88 }
89 }
90
91 return comparison;
92 }
93
94
95
96
97
98
99 @Override
100 public PlantUMLClassesDiagramElement deepClone() {
101 AbstractPlantUMLClassesDiagramElement a = null;
102
103 try {
104 a = (AbstractPlantUMLClassesDiagramElement) super.clone();
105 } catch (final CloneNotSupportedException cnse) {
106 LOGGER.log(SEVERE, UNEXPECTED_ERROR, cnse);
107 }
108
109 return a;
110 }
111
112
113
114
115
116
117 @Override
118 public boolean equals(final Object obj) {
119 if (this == obj) {
120 return true;
121 }
122 if (obj == null) {
123 return false;
124 }
125 if (getClass() != obj.getClass()) {
126 return false;
127 }
128 final AbstractPlantUMLClassesDiagramElement other = (AbstractPlantUMLClassesDiagramElement) obj;
129 if (elementTag == null) {
130 if (other.elementTag != null) {
131 return false;
132 }
133 } else if (!elementTag.equals(other.elementTag)) {
134 return false;
135 }
136 if (name == null) {
137 if (other.name != null) {
138 return false;
139 }
140 } else if (!name.equals(other.name)) {
141 return false;
142 }
143 return true;
144 }
145
146
147
148
149
150
151
152 protected abstract String getAdditionalPlantUMLTextDescription();
153
154
155
156
157
158
159 @Override
160 public PlantUMLClassesDiagramElementTag getElementTag() {
161 return elementTag;
162 }
163
164
165
166
167
168
169 @Override
170 public String getName() {
171 return name;
172 }
173
174
175
176
177
178
179 @Override
180 public String getPlantUMLTextDescription() {
181 return getElementTag().getTagName() + getName() + getAdditionalPlantUMLTextDescription();
182 }
183
184
185
186
187
188
189 @Override
190 public int hashCode() {
191 final int prime = 31;
192 int result = 1;
193 result = prime * result + ((elementTag == null) ? 0 : elementTag.hashCode());
194 result = prime * result + ((name == null) ? 0 : name.hashCode());
195 return result;
196 }
197
198
199
200
201
202
203 @Override
204 public String toString() {
205 return "elementTag=" + elementTag + ", name=" + name;
206 }
207 }