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.settings;
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 to activate
20   * its profile.
21   */
22  @Experimental
23  @Generated @ThreadSafe @Immutable
24  public class ActivationOS
25      implements Serializable, InputLocationTracker
26  {
27      /**
28       * The name of the OS to be used to activate a profile.
29       */
30      final String name;
31      /**
32       * The general family of the OS to be used to activate a
33       * profile (e.g. 'windows')
34       */
35      final String family;
36      /**
37       * The architecture of the OS to be used to activate a profile.
38       */
39      final String arch;
40      /**
41       * The version of the OS to be used to activate a profile.
42       */
43      final String version;
44      /** Locations */
45      final Map<Object, InputLocation> locations;
46  
47      /**
48        * Constructor for this class, package protected.
49        * @see Builder#build()
50        */
51      ActivationOS(
52          String name,
53          String family,
54          String arch,
55          String version,
56          Map<Object, InputLocation> locations
57      ) {
58          this.name = name;
59          this.family = family;
60          this.arch = arch;
61          this.version = version;
62          this.locations = ImmutableCollections.copy(locations);
63      }
64  
65      /**
66       * The name of the OS to be used to activate a profile.
67       *
68       * @return a {@code String}
69       */
70      public String getName() {
71          return this.name;
72      }
73  
74      /**
75       * The general family of the OS to be used to activate a
76       * profile (e.g. 'windows')
77       *
78       * @return a {@code String}
79       */
80      public String getFamily() {
81          return this.family;
82      }
83  
84      /**
85       * The architecture of the OS to be used to activate a profile.
86       *
87       * @return a {@code String}
88       */
89      public String getArch() {
90          return this.arch;
91      }
92  
93      /**
94       * The version of the OS to be used to activate a profile.
95       *
96       * @return a {@code String}
97       */
98      public String getVersion() {
99          return this.version;
100     }
101 
102     /**
103      * Gets the location of the specified field in the input source.
104      */
105     public InputLocation getLocation(Object key) {
106         return locations != null ? locations.get(key) : null;
107     }
108 
109     /**
110      * Creates a new builder with this object as the basis.
111      *
112      * @return a {@code Builder}
113      */
114     @Nonnull
115     public Builder with() {
116         return newBuilder(this);
117     }
118     /**
119      * Creates a new {@code ActivationOS} instance using the specified name.
120      *
121      * @param name the new {@code String} to use
122      * @return a {@code ActivationOS} with the specified name
123      */
124     @Nonnull
125     public ActivationOS withName(String name) {
126         return newBuilder(this, true).name(name).build();
127     }
128     /**
129      * Creates a new {@code ActivationOS} instance using the specified family.
130      *
131      * @param family the new {@code String} to use
132      * @return a {@code ActivationOS} with the specified family
133      */
134     @Nonnull
135     public ActivationOS withFamily(String family) {
136         return newBuilder(this, true).family(family).build();
137     }
138     /**
139      * Creates a new {@code ActivationOS} instance using the specified arch.
140      *
141      * @param arch the new {@code String} to use
142      * @return a {@code ActivationOS} with the specified arch
143      */
144     @Nonnull
145     public ActivationOS withArch(String arch) {
146         return newBuilder(this, true).arch(arch).build();
147     }
148     /**
149      * Creates a new {@code ActivationOS} instance using the specified version.
150      *
151      * @param version the new {@code String} to use
152      * @return a {@code ActivationOS} with the specified version
153      */
154     @Nonnull
155     public ActivationOS withVersion(String version) {
156         return newBuilder(this, true).version(version).build();
157     }
158 
159     /**
160      * Creates a new {@code ActivationOS} instance.
161      * Equivalent to {@code newInstance(true)}.
162      * @see #newInstance(boolean)
163      *
164      * @return a new {@code ActivationOS}
165      */
166     @Nonnull
167     public static ActivationOS newInstance() {
168         return newInstance(true);
169     }
170 
171     /**
172      * Creates a new {@code ActivationOS} instance using default values or not.
173      * Equivalent to {@code newBuilder(withDefaults).build()}.
174      *
175      * @param withDefaults the boolean indicating whether default values should be used
176      * @return a new {@code ActivationOS}
177      */
178     @Nonnull
179     public static ActivationOS newInstance(boolean withDefaults) {
180         return newBuilder(withDefaults).build();
181     }
182 
183     /**
184      * Creates a new {@code ActivationOS} builder instance.
185      * Equivalent to {@code newBuilder(true)}.
186      * @see #newBuilder(boolean)
187      *
188      * @return a new {@code Builder}
189      */
190     @Nonnull
191     public static Builder newBuilder() {
192         return newBuilder(true);
193     }
194 
195     /**
196      * Creates a new {@code ActivationOS} builder instance using default values or not.
197      *
198      * @param withDefaults the boolean indicating whether default values should be used
199      * @return a new {@code Builder}
200      */
201     @Nonnull
202     public static Builder newBuilder(boolean withDefaults) {
203         return new Builder(withDefaults);
204     }
205 
206     /**
207      * Creates a new {@code ActivationOS} builder instance using the specified object as a basis.
208      * Equivalent to {@code newBuilder(from, false)}.
209      *
210      * @param from the {@code ActivationOS} instance to use as a basis
211      * @return a new {@code Builder}
212      */
213     @Nonnull
214     public static Builder newBuilder(ActivationOS from) {
215         return newBuilder(from, false);
216     }
217 
218     /**
219      * Creates a new {@code ActivationOS} builder instance using the specified object as a basis.
220      *
221      * @param from the {@code ActivationOS} instance to use as a basis
222      * @param forceCopy the boolean indicating if a copy should be forced
223      * @return a new {@code Builder}
224      */
225     @Nonnull
226     public static Builder newBuilder(ActivationOS from, boolean forceCopy) {
227         return new Builder(from, forceCopy);
228     }
229 
230     /**
231      * Builder class used to create ActivationOS instances.
232      * @see #with()
233      * @see #newBuilder()
234      */
235     @NotThreadSafe
236     public static class Builder
237     {
238         ActivationOS base;
239         String name;
240         String family;
241         String arch;
242         String version;
243         Map<Object, InputLocation> locations;
244 
245         Builder(boolean withDefaults) {
246             if (withDefaults) {
247             }
248         }
249 
250         Builder(ActivationOS base, boolean forceCopy) {
251             if (forceCopy) {
252                 this.name = base.name;
253                 this.family = base.family;
254                 this.arch = base.arch;
255                 this.version = base.version;
256                 this.locations = base.locations;
257             } else {
258                 this.base = base;
259             }
260         }
261 
262         @Nonnull
263         public Builder name(String name) {
264             this.name = name;
265             return this;
266         }
267 
268         @Nonnull
269         public Builder family(String family) {
270             this.family = family;
271             return this;
272         }
273 
274         @Nonnull
275         public Builder arch(String arch) {
276             this.arch = arch;
277             return this;
278         }
279 
280         @Nonnull
281         public Builder version(String version) {
282             this.version = version;
283             return this;
284         }
285 
286 
287         @Nonnull
288         public Builder location(Object key, InputLocation location) {
289             if (location != null) {
290                 if (!(this.locations instanceof HashMap)) {
291                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
292                 }
293                 this.locations.put(key, location);
294             }
295             return this;
296         }
297 
298         @Nonnull
299         public ActivationOS build() {
300             if (base != null
301                     && (name == null || name == base.name)
302                     && (family == null || family == base.family)
303                     && (arch == null || arch == base.arch)
304                     && (version == null || version == base.version)
305             ) {
306                 return base;
307             }
308             Map<Object, InputLocation> newlocs = this.locations != null ? this.locations : Collections.emptyMap();
309             Map<Object, InputLocation> oldlocs = this.base != null && this.base.locations != null ? this.base.locations : Collections.emptyMap();
310             Map<Object, InputLocation> locations = new HashMap<>();
311             locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
312             locations.put("name", newlocs.containsKey("name") ? newlocs.get("name") : oldlocs.get("name"));
313             locations.put("family", newlocs.containsKey("family") ? newlocs.get("family") : oldlocs.get("family"));
314             locations.put("arch", newlocs.containsKey("arch") ? newlocs.get("arch") : oldlocs.get("arch"));
315             locations.put("version", newlocs.containsKey("version") ? newlocs.get("version") : oldlocs.get("version"));
316             return new ActivationOS(
317                 name != null ? name : (base != null ? base.name : null),
318                 family != null ? family : (base != null ? base.family : null),
319                 arch != null ? arch : (base != null ? base.arch : null),
320                 version != null ? version : (base != null ? base.version : null),
321                 locations
322             );
323         }
324     }
325 
326 }