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