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