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;
26
27 import static java.util.Collections.unmodifiableMap;
28 import static java.util.logging.Level.FINE;
29 import static java.util.logging.Logger.getLogger;
30 import static net.sourceforge.plantumldependency.cli.constants.log.ErrorConstants.PROGRAMMING_LANGUAGE_NAME_NULL_ERROR;
31 import static net.sourceforge.plantumldependency.cli.constants.log.ErrorConstants.UNKNOWN_PROGRAMMING_LANGUAGE_ERROR;
32 import static net.sourceforge.plantumldependency.cli.constants.log.FineConstants.PROGRAMMING_LANGUAGE_FOUND_FINE;
33 import static net.sourceforge.plantumldependency.common.utils.check.ParameterCheckerUtils.checkNullOrEmpty;
34 import static net.sourceforge.plantumldependency.common.utils.comparable.ComparableResult.EQUAL;
35 import static net.sourceforge.plantumldependency.common.utils.log.LogUtils.buildLogString;
36
37 import java.io.Serializable;
38 import java.util.Collection;
39 import java.util.Map;
40 import java.util.Set;
41 import java.util.TreeMap;
42 import java.util.TreeSet;
43 import java.util.logging.Logger;
44 import java.util.regex.Pattern;
45
46 import net.sourceforge.plantumldependency.cli.exception.PlantUMLDependencyException;
47 import net.sourceforge.plantumldependency.cli.generic.GenericDependency;
48 import net.sourceforge.plantumldependency.cli.main.option.display.type.argument.DisplayType;
49 import net.sourceforge.plantumldependency.cli.main.option.programminglanguage.context.ProgrammingLanguageContext;
50
51
52
53
54
55
56
57
58
59 public abstract class ProgrammingLanguage implements Comparable < ProgrammingLanguage >, Serializable {
60
61
62 private static final long serialVersionUID = -4593346488847506817L;
63
64
65 private static final transient Logger LOGGER = getLogger(ProgrammingLanguage.class.getName());
66
67
68 public static final ProgrammingLanguage JAVA = new JavaProgrammingLanguage("java");
69
70
71 public static final ProgrammingLanguage CPP = new CppProgrammingLanguage("cpp");
72
73
74 private static final Map < String, ProgrammingLanguage > PROGRAMMING_LANGUAGE_MAP = createProgrammingLanguageMap();
75
76
77
78
79
80
81
82
83 private static Map < String, ProgrammingLanguage > createProgrammingLanguageMap() {
84 final Map < String, ProgrammingLanguage > programmingLanguageMap = new TreeMap < String, ProgrammingLanguage >();
85
86 programmingLanguageMap.put(CPP.getName(), CPP);
87 programmingLanguageMap.put(JAVA.getName(), JAVA);
88
89 return unmodifiableMap(programmingLanguageMap);
90 }
91
92
93
94
95
96
97
98 public static Collection < ProgrammingLanguage > getProgrammingLanguageCollection() {
99 return PROGRAMMING_LANGUAGE_MAP.values();
100 }
101
102
103
104
105
106
107
108 public static Set < String > getProgrammingLanguageNamesSet() {
109 final Set < String > names = new TreeSet < String >();
110
111 for (final ProgrammingLanguage programmingLanguage : getProgrammingLanguageCollection()) {
112 names.add(programmingLanguage.getName());
113 }
114
115 return names;
116 }
117
118
119
120
121
122
123
124
125
126
127
128 public static ProgrammingLanguage valueOfIgnoringCase(final String programmingLanguageName) {
129 checkNullOrEmpty(programmingLanguageName, PROGRAMMING_LANGUAGE_NAME_NULL_ERROR);
130
131 ProgrammingLanguage programmingLanguage = null;
132
133 programmingLanguage = PROGRAMMING_LANGUAGE_MAP.get(programmingLanguageName.toLowerCase());
134 if (programmingLanguage != null) {
135 LOGGER.log(FINE, buildLogString(PROGRAMMING_LANGUAGE_FOUND_FINE, programmingLanguage));
136 } else {
137 throw new IllegalArgumentException(buildLogString(UNKNOWN_PROGRAMMING_LANGUAGE_ERROR,
138 programmingLanguageName));
139 }
140
141 return programmingLanguage;
142 }
143
144
145 private String name;
146
147
148
149
150
151
152
153
154
155 protected ProgrammingLanguage(final String programmingLanguageName) {
156 setName(programmingLanguageName);
157 }
158
159
160
161
162
163
164 @Override
165 public int compareTo(final ProgrammingLanguage o) {
166 if (this == o) {
167 return EQUAL.getResult();
168 }
169
170 return getName().compareTo(o.getName());
171 }
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188 public abstract ProgrammingLanguageContext createNewContext(final Set < DisplayType > displayTypesOpts,
189 final Pattern displayPackageNamePattern, final Pattern displayNamePattern);
190
191
192
193
194
195
196 @Override
197 public boolean equals(final Object obj) {
198 if (this == obj) {
199 return true;
200 }
201 if (obj == null) {
202 return false;
203 }
204 if (getClass() != obj.getClass()) {
205 return false;
206 }
207 final ProgrammingLanguage other = (ProgrammingLanguage) obj;
208 if (name == null) {
209 if (other.name != null) {
210 return false;
211 }
212 } else if (!name.equals(other.name)) {
213 return false;
214 }
215 return true;
216 }
217
218
219
220
221
222
223
224 public String getName() {
225 return name;
226 }
227
228
229
230
231
232
233 @Override
234 public int hashCode() {
235 final int prime = 31;
236 int result = 1;
237 result = prime * result + ((name == null) ? 0 : name.hashCode());
238 return result;
239 }
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261 public abstract GenericDependency readDependencyFromFile(String sourceFileContent,
262 ProgrammingLanguageContext programmingLanguageContext) throws PlantUMLDependencyException;
263
264
265
266
267
268
269
270
271
272 private void setName(final String value) {
273 checkNullOrEmpty(value, PROGRAMMING_LANGUAGE_NAME_NULL_ERROR);
274
275 name = value;
276 }
277
278
279
280
281
282
283 @Override
284 public String toString() {
285 return getClass().getSimpleName() + " [name=" + name + "]";
286 }
287 }