View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   //   Generated by Maven, any modifications will be overwritten.
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   * This is an activator which will detect an operating system's attributes in order
19   * to activate its profile.
20   */
21  @Experimental
22  @Generated @ThreadSafe @Immutable
23  public class ActivationOS
24      implements Serializable, InputLocationTracker
25  {
26      /**
27       * The name of the operating system to be used to activate the profile. This must be an exact match
28       * of the {@code ${os.name}} Java property, such as {@code Windows XP}.
29       */
30      final String name;
31      /**
32       * The general family of the OS to be used to activate the profile, such as
33       * {@code windows} or {@code unix}.
34       */
35      final String family;
36      /**
37       * The architecture of the operating system to be used to activate the
38       * profile.
39       */
40      final String arch;
41      /**
42       * The version of the operating system to be used to activate the
43       * profile.
44       */
45      final String version;
46      /** Location of the xml element for this object. */
47      final InputLocation location;
48      /** Location of the xml element for the field name. */
49      final InputLocation nameLocation;
50      /** Location of the xml element for the field family. */
51      final InputLocation familyLocation;
52      /** Location of the xml element for the field arch. */
53      final InputLocation archLocation;
54      /** Location of the xml element for the field version. */
55      final InputLocation versionLocation;
56      /** Other locations */
57      final Map<Object, InputLocation> locations;
58  
59      /**
60        * Constructor for this class, package protected.
61        * @see Builder#build()
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       * The name of the operating system to be used to activate the profile. This must be an exact match
90       * of the {@code ${os.name}} Java property, such as {@code Windows XP}.
91       *
92       * @return a {@code String}
93       */
94      public String getName()
95      {
96          return this.name;
97      }
98  
99      /**
100      * The general family of the OS to be used to activate the profile, such as
101      * {@code windows} or {@code unix}.
102      *
103      * @return a {@code String}
104      */
105     public String getFamily()
106     {
107         return this.family;
108     }
109 
110     /**
111      * The architecture of the operating system to be used to activate the
112      * profile.
113      *
114      * @return a {@code String}
115      */
116     public String getArch()
117     {
118         return this.arch;
119     }
120 
121     /**
122      * The version of the operating system to be used to activate the
123      * profile.
124      *
125      * @return a {@code String}
126      */
127     public String getVersion()
128     {
129         return this.version;
130     }
131 
132     /**
133      * Gets the location of the specified field in the input source.
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      * Creates a new builder with this object as the basis.
158      *
159      * @return a {@code Builder}
160      */
161     @Nonnull
162     public Builder with()
163     {
164         return newBuilder( this );
165     }
166     /**
167      * Creates a new {@code ActivationOS} instance using the specified name.
168      *
169      * @param name the new {@code String} to use
170      * @return a {@code ActivationOS} with the specified name
171      */
172     @Nonnull
173     public ActivationOS withName( String name )
174     {
175         return with().name( name ).build();
176     }
177     /**
178      * Creates a new {@code ActivationOS} instance using the specified family.
179      *
180      * @param family the new {@code String} to use
181      * @return a {@code ActivationOS} with the specified family
182      */
183     @Nonnull
184     public ActivationOS withFamily( String family )
185     {
186         return with().family( family ).build();
187     }
188     /**
189      * Creates a new {@code ActivationOS} instance using the specified arch.
190      *
191      * @param arch the new {@code String} to use
192      * @return a {@code ActivationOS} with the specified arch
193      */
194     @Nonnull
195     public ActivationOS withArch( String arch )
196     {
197         return with().arch( arch ).build();
198     }
199     /**
200      * Creates a new {@code ActivationOS} instance using the specified version.
201      *
202      * @param version the new {@code String} to use
203      * @return a {@code ActivationOS} with the specified version
204      */
205     @Nonnull
206     public ActivationOS withVersion( String version )
207     {
208         return with().version( version ).build();
209     }
210 
211     /**
212      * Creates a new {@code ActivationOS} instance.
213      * Equivalent to {@code newInstance( true )}.
214      * @see #newInstance(boolean)
215      *
216      * @return a new {@code ActivationOS}
217      */
218     @Nonnull
219     public static ActivationOS newInstance()
220     {
221         return newInstance( true );
222     }
223 
224     /**
225      * Creates a new {@code ActivationOS} instance using default values or not.
226      * Equivalent to {@code newBuilder( withDefaults ).build()}.
227      *
228      * @param withDefaults the boolean indicating whether default values should be used
229      * @return a new {@code ActivationOS}
230      */
231     @Nonnull
232     public static ActivationOS newInstance( boolean withDefaults )
233     {
234         return newBuilder( withDefaults ).build();
235     }
236 
237     /**
238      * Creates a new {@code ActivationOS} builder instance.
239      * Equivalent to {@code newBuilder( true )}.
240      * @see #newBuilder(boolean)
241      *
242      * @return a new {@code Builder}
243      */
244     @Nonnull
245     public static Builder newBuilder()
246     {
247         return newBuilder( true );
248     }
249 
250     /**
251      * Creates a new {@code ActivationOS} builder instance using default values or not.
252      *
253      * @param withDefaults the boolean indicating whether default values should be used
254      * @return a new {@code Builder}
255      */
256     @Nonnull
257     public static Builder newBuilder( boolean withDefaults )
258     {
259         return new Builder( withDefaults );
260     }
261 
262     /**
263      * Creates a new {@code ActivationOS} builder instance using the specified object as a basis.
264      * Equivalent to {@code newBuilder( from, false )}.
265      *
266      * @param from the {@code ActivationOS} instance to use as a basis
267      * @return a new {@code Builder}
268      */
269     @Nonnull
270     public static Builder newBuilder( ActivationOS from )
271     {
272         return newBuilder( from, false );
273     }
274 
275     /**
276      * Creates a new {@code ActivationOS} builder instance using the specified object as a basis.
277      *
278      * @param from the {@code ActivationOS} instance to use as a basis
279      * @param forceCopy the boolean indicating if a copy should be forced
280      * @return a new {@code Builder}
281      */
282     @Nonnull
283     public static Builder newBuilder( ActivationOS from, boolean forceCopy )
284     {
285         return new Builder( from, forceCopy );
286     }
287 
288     /**
289      * Builder class used to create ActivationOS instances.
290      * @see #with()
291      * @see #newBuilder()
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 }