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