1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.index.reader;
20
21 import java.util.Map;
22 import java.util.Objects;
23
24 import static java.util.Objects.requireNonNull;
25
26
27
28
29
30
31 public final class Record {
32
33
34
35 public static final class EntryKey {
36 private final String name;
37
38 private final Class<?> proto;
39
40 public EntryKey(final String name, final Class<?> proto) {
41 requireNonNull(name, "name is null");
42 requireNonNull(proto, "proto is null");
43 this.name = name;
44 this.proto = proto;
45 }
46
47 public String getName() {
48 return name;
49 }
50
51 public Class<?> getProto() {
52 return proto;
53 }
54
55 @Override
56 public boolean equals(Object o) {
57 if (this == o) {
58 return true;
59 }
60 if (o == null || getClass() != o.getClass()) {
61 return false;
62 }
63 EntryKey entryKey = (EntryKey) o;
64 return Objects.equals(name, entryKey.name);
65 }
66
67 @Override
68 public int hashCode() {
69 return Objects.hash(name);
70 }
71
72 @Override
73 public String toString() {
74 return "Key{" + "name='" + name + '\'' + ", type=" + proto.getSimpleName() + '}';
75 }
76 }
77
78
79
80
81 public static final EntryKey REPOSITORY_ID = new EntryKey("repositoryId", String.class);
82
83
84
85
86 public static final EntryKey ALL_GROUPS = new EntryKey("allGroups", String[].class);
87
88
89
90
91 public static final EntryKey ROOT_GROUPS = new EntryKey("rootGroups", String[].class);
92
93
94
95
96
97 public static final EntryKey REC_MODIFIED = new EntryKey("recordModified", Long.class);
98
99
100
101
102 public static final EntryKey GROUP_ID = new EntryKey("groupId", String.class);
103
104
105
106
107 public static final EntryKey ARTIFACT_ID = new EntryKey("artifactId", String.class);
108
109
110
111
112 public static final EntryKey VERSION = new EntryKey("version", String.class);
113
114
115
116
117 public static final EntryKey CLASSIFIER = new EntryKey("classifier", String.class);
118
119
120
121
122 public static final EntryKey PACKAGING = new EntryKey("packaging", String.class);
123
124
125
126
127 public static final EntryKey FILE_EXTENSION = new EntryKey("fileExtension", String.class);
128
129
130
131
132 public static final EntryKey FILE_MODIFIED = new EntryKey("fileModified", Long.class);
133
134
135
136
137 public static final EntryKey FILE_SIZE = new EntryKey("fileSize", Long.class);
138
139
140
141
142 public static final EntryKey HAS_SOURCES = new EntryKey("hasSources", Boolean.class);
143
144
145
146
147 public static final EntryKey HAS_JAVADOC = new EntryKey("hasJavadoc", Boolean.class);
148
149
150
151
152 public static final EntryKey HAS_SIGNATURE = new EntryKey("hasSignature", Boolean.class);
153
154
155
156
157 public static final EntryKey NAME = new EntryKey("name", String.class);
158
159
160
161
162 public static final EntryKey DESCRIPTION = new EntryKey("description", String.class);
163
164
165
166
167 public static final EntryKey SHA1 = new EntryKey("sha1", String.class);
168
169
170
171
172
173 public static final EntryKey CLASSNAMES = new EntryKey("classNames", String[].class);
174
175
176
177
178
179 public static final EntryKey PLUGIN_PREFIX = new EntryKey("pluginPrefix", String.class);
180
181
182
183
184
185 public static final EntryKey PLUGIN_GOALS = new EntryKey("pluginGoals", String[].class);
186
187
188
189
190
191 public static final EntryKey OSGI_BUNDLE_SYMBOLIC_NAME = new EntryKey("Bundle-SymbolicName", String.class);
192
193
194
195
196
197 public static final EntryKey OSGI_BUNDLE_VERSION = new EntryKey("Bundle-Version", String.class);
198
199
200
201
202
203 public static final EntryKey OSGI_EXPORT_PACKAGE = new EntryKey("Export-Package", String.class);
204
205
206
207
208
209 public static final EntryKey OSGI_EXPORT_SERVICE = new EntryKey("Export-Service", String.class);
210
211
212
213
214
215 public static final EntryKey OSGI_BUNDLE_DESCRIPTION = new EntryKey("Bundle-Description", String.class);
216
217
218
219
220
221 public static final EntryKey OSGI_BUNDLE_NAME = new EntryKey("Bundle-Name", String.class);
222
223
224
225
226
227 public static final EntryKey OSGI_BUNDLE_LICENSE = new EntryKey("Bundle-License", String.class);
228
229
230
231
232
233 public static final EntryKey OSGI_EXPORT_DOCURL = new EntryKey("Bundle-DocURL", String.class);
234
235
236
237
238
239 public static final EntryKey OSGI_IMPORT_PACKAGE = new EntryKey("Import-Package", String.class);
240
241
242
243
244
245 public static final EntryKey OSGI_REQUIRE_BUNDLE = new EntryKey("Require-Bundle", String.class);
246
247
248
249
250
251 public static final EntryKey OSGI_PROVIDE_CAPABILITY = new EntryKey("Provide-Capability", String.class);
252
253
254
255
256
257 public static final EntryKey OSGI_REQUIRE_CAPABILITY = new EntryKey("Require-Capability", String.class);
258
259
260
261
262
263 public static final EntryKey OSGI_FRAGMENT_HOST = new EntryKey("Fragment-Host", String.class);
264
265
266
267
268
269 public static final EntryKey OSGI_BREE = new EntryKey("Bundle-RequiredExecutionEnvironment", String.class);
270
271
272
273
274
275 public static final EntryKey SHA_256 = new EntryKey("sha256", String.class);
276
277
278
279
280 public enum Type {
281
282
283
284
285
286
287
288 DESCRIPTOR,
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314 ARTIFACT_ADD,
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330 ARTIFACT_REMOVE,
331
332
333
334
335
336
337
338
339 ALL_GROUPS,
340
341
342
343
344
345
346
347
348
349 ROOT_GROUPS
350 }
351
352 private final Type type;
353
354 private final Map<EntryKey, Object> expanded;
355
356 public Record(final Type type, final Map<EntryKey, Object> expanded) {
357 this.type = type;
358 this.expanded = expanded;
359 }
360
361
362
363
364
365
366 public Type getType() {
367 return type;
368 }
369
370
371
372
373 public Map<EntryKey, Object> getExpanded() {
374 return expanded;
375 }
376
377
378
379
380 boolean containsKey(final EntryKey entryKey) {
381 return expanded.containsKey(entryKey);
382 }
383
384
385
386
387 public Object get(final EntryKey entryKey) {
388 return expanded.get(entryKey);
389 }
390
391
392
393
394
395
396 public String getString(final EntryKey entryKey) {
397 if (!String.class.isAssignableFrom(entryKey.proto)) {
398 throw new IllegalArgumentException(
399 "Key " + entryKey + " does not hold type compatible to java.lang.String");
400 }
401 return (String) expanded.get(entryKey);
402 }
403
404
405
406
407
408
409 public String[] getStringArray(final EntryKey entryKey) {
410 if (!String[].class.isAssignableFrom(entryKey.proto)) {
411 throw new IllegalArgumentException(
412 "Key " + entryKey + " does not hold type compatible to java.lang.String[]");
413 }
414 return (String[]) expanded.get(entryKey);
415 }
416
417
418
419
420
421
422 public Long getLong(final EntryKey entryKey) {
423 if (!Long.class.isAssignableFrom(entryKey.proto)) {
424 throw new IllegalArgumentException("Key " + entryKey + " does not hold type compatible to java.lang.Long");
425 }
426 return (Long) expanded.get(entryKey);
427 }
428
429
430
431
432
433
434 public Boolean getBoolean(final EntryKey entryKey) {
435 if (!Boolean.class.isAssignableFrom(entryKey.proto)) {
436 throw new IllegalArgumentException(
437 "Key " + entryKey + " does not hold type compatible to java.lang.Boolean");
438 }
439 return (Boolean) expanded.get(entryKey);
440 }
441
442
443
444
445 public Object put(final EntryKey entryKey, final Object value) {
446 if (value == null) {
447 return expanded.remove(entryKey);
448 } else {
449 if (!entryKey.proto.isAssignableFrom(value.getClass())) {
450 throw new IllegalArgumentException("Key " + entryKey + " does not accepts value " + value);
451 }
452 return expanded.put(entryKey, value);
453 }
454 }
455
456 @Override
457 public String toString() {
458 return "Record{" + "type=" + type + ", expanded=" + expanded + '}';
459 }
460 }