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