1
2
3
4 package org.apache.maven.api.model;
5
6 import java.io.Serializable;
7 import java.util.Collections;
8 import java.util.HashMap;
9 import java.util.Map;
10 import org.apache.maven.api.annotations.Experimental;
11 import org.apache.maven.api.annotations.Generated;
12 import org.apache.maven.api.annotations.Immutable;
13 import org.apache.maven.api.annotations.Nonnull;
14 import org.apache.maven.api.annotations.NotThreadSafe;
15 import org.apache.maven.api.annotations.ThreadSafe;
16
17
18
19
20
21 @Experimental
22 @Generated @ThreadSafe @Immutable
23 public class ActivationOS
24 implements Serializable, InputLocationTracker
25 {
26
27
28
29
30 final String name;
31
32
33
34
35 final String family;
36
37
38
39
40 final String arch;
41
42
43
44
45 final String version;
46
47 final InputLocation location;
48
49 final InputLocation nameLocation;
50
51 final InputLocation familyLocation;
52
53 final InputLocation archLocation;
54
55 final InputLocation versionLocation;
56
57 final Map<Object, InputLocation> locations;
58
59
60
61
62
63 ActivationOS(
64 String name,
65 String family,
66 String arch,
67 String version,
68 Map<Object, InputLocation> locations,
69 InputLocation location,
70 InputLocation nameLocation,
71 InputLocation familyLocation,
72 InputLocation archLocation,
73 InputLocation versionLocation
74 )
75 {
76 this.name = name;
77 this.family = family;
78 this.arch = arch;
79 this.version = version;
80 this.locations = ImmutableCollections.copy( locations );
81 this.location = location;
82 this.nameLocation = nameLocation;
83 this.familyLocation = familyLocation;
84 this.archLocation = archLocation;
85 this.versionLocation = versionLocation;
86 }
87
88
89
90
91
92
93
94 public String getName()
95 {
96 return this.name;
97 }
98
99
100
101
102
103
104
105 public String getFamily()
106 {
107 return this.family;
108 }
109
110
111
112
113
114
115
116 public String getArch()
117 {
118 return this.arch;
119 }
120
121
122
123
124
125
126
127 public String getVersion()
128 {
129 return this.version;
130 }
131
132
133
134
135 public InputLocation getLocation( Object key )
136 {
137 if ( key instanceof String )
138 {
139 switch ( ( String ) key )
140 {
141 case "":
142 return location;
143 case "name":
144 return nameLocation;
145 case "family":
146 return familyLocation;
147 case "arch":
148 return archLocation;
149 case "version":
150 return versionLocation;
151 }
152 }
153 return locations != null ? locations.get( key ) : null;
154 }
155
156
157
158
159
160
161 @Nonnull
162 public Builder with()
163 {
164 return newBuilder( this );
165 }
166
167
168
169
170
171
172 @Nonnull
173 public ActivationOS withName( String name )
174 {
175 return with().name( name ).build();
176 }
177
178
179
180
181
182
183 @Nonnull
184 public ActivationOS withFamily( String family )
185 {
186 return with().family( family ).build();
187 }
188
189
190
191
192
193
194 @Nonnull
195 public ActivationOS withArch( String arch )
196 {
197 return with().arch( arch ).build();
198 }
199
200
201
202
203
204
205 @Nonnull
206 public ActivationOS withVersion( String version )
207 {
208 return with().version( version ).build();
209 }
210
211
212
213
214
215
216
217
218 @Nonnull
219 public static ActivationOS newInstance()
220 {
221 return newInstance( true );
222 }
223
224
225
226
227
228
229
230
231 @Nonnull
232 public static ActivationOS newInstance( boolean withDefaults )
233 {
234 return newBuilder( withDefaults ).build();
235 }
236
237
238
239
240
241
242
243
244 @Nonnull
245 public static Builder newBuilder()
246 {
247 return newBuilder( true );
248 }
249
250
251
252
253
254
255
256 @Nonnull
257 public static Builder newBuilder( boolean withDefaults )
258 {
259 return new Builder( withDefaults );
260 }
261
262
263
264
265
266
267
268
269 @Nonnull
270 public static Builder newBuilder( ActivationOS from )
271 {
272 return newBuilder( from, false );
273 }
274
275
276
277
278
279
280
281
282 @Nonnull
283 public static Builder newBuilder( ActivationOS from, boolean forceCopy )
284 {
285 return new Builder( from, forceCopy );
286 }
287
288
289
290
291
292
293 @NotThreadSafe
294 public static class Builder
295 {
296 ActivationOS base;
297 String name;
298 String family;
299 String arch;
300 String version;
301 Map<Object, InputLocation> locations;
302
303 Builder( boolean withDefaults )
304 {
305 if ( withDefaults )
306 {
307 }
308 }
309
310 Builder( ActivationOS base, boolean forceCopy )
311 {
312 if ( forceCopy )
313 {
314 this.name = base.name;
315 this.family = base.family;
316 this.arch = base.arch;
317 this.version = base.version;
318 }
319 else
320 {
321 this.base = base;
322 }
323 }
324
325 @Nonnull
326 public Builder name( String name )
327 {
328 this.name = name;
329 return this;
330 }
331
332 @Nonnull
333 public Builder family( String family )
334 {
335 this.family = family;
336 return this;
337 }
338
339 @Nonnull
340 public Builder arch( String arch )
341 {
342 this.arch = arch;
343 return this;
344 }
345
346 @Nonnull
347 public Builder version( String version )
348 {
349 this.version = version;
350 return this;
351 }
352
353
354 @Nonnull
355 public Builder location( Object key, InputLocation location )
356 {
357 if ( location != null )
358 {
359 if ( this.locations == null )
360 {
361 this.locations = new HashMap<>();
362 }
363 this.locations.put( key, location );
364 }
365 return this;
366 }
367
368 @Nonnull
369 public ActivationOS build()
370 {
371 if ( base != null
372 && ( name == null || name == base.name )
373 && ( family == null || family == base.family )
374 && ( arch == null || arch == base.arch )
375 && ( version == null || version == base.version )
376 )
377 {
378 return base;
379 }
380 Map<Object, InputLocation> locations = null;
381 InputLocation location = null;
382 InputLocation nameLocation = null;
383 InputLocation familyLocation = null;
384 InputLocation archLocation = null;
385 InputLocation versionLocation = null;
386 if ( this.locations != null )
387 {
388 locations = this.locations;
389 location = locations.remove( "" );
390 nameLocation = locations.remove( "name" );
391 familyLocation = locations.remove( "family" );
392 archLocation = locations.remove( "arch" );
393 versionLocation = locations.remove( "version" );
394 }
395 return new ActivationOS(
396 name != null ? name : ( base != null ? base.name : null ),
397 family != null ? family : ( base != null ? base.family : null ),
398 arch != null ? arch : ( base != null ? base.arch : null ),
399 version != null ? version : ( base != null ? base.version : null ),
400 locations != null ? locations : ( base != null ? base.locations : null ),
401 location != null ? location : ( base != null ? base.location : null ),
402 nameLocation != null ? nameLocation : ( base != null ? base.nameLocation : null ),
403 familyLocation != null ? familyLocation : ( base != null ? base.familyLocation : null ),
404 archLocation != null ? archLocation : ( base != null ? base.archLocation : null ),
405 versionLocation != null ? versionLocation : ( base != null ? base.versionLocation : null )
406 );
407 }
408 }
409
410 }