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 the property specification used to activate a profile. If the value field
20   * is empty, then the existence of the named property will activate the profile, otherwise it
21   * does a case-sensitive match against the property value as well.
22   */
23  @Experimental
24  @Generated @ThreadSafe @Immutable
25  public class ActivationProperty
26      implements Serializable, InputLocationTracker
27  {
28      /**
29       * The name of the property to be used to activate a profile.
30       */
31      final String name;
32      /**
33       * The value of the property required to activate a profile.
34       */
35      final String value;
36      /** Locations */
37      final Map<Object, InputLocation> locations;
38  
39      /**
40        * Constructor for this class, package protected.
41        * @see Builder#build()
42        */
43      ActivationProperty(
44          String name,
45          String value,
46          Map<Object, InputLocation> locations
47      ) {
48          this.name = name;
49          this.value = value;
50          this.locations = ImmutableCollections.copy(locations);
51      }
52  
53      /**
54       * The name of the property to be used to activate a profile.
55       *
56       * @return a {@code String}
57       */
58      public String getName() {
59          return this.name;
60      }
61  
62      /**
63       * The value of the property required to activate a profile.
64       *
65       * @return a {@code String}
66       */
67      public String getValue() {
68          return this.value;
69      }
70  
71      /**
72       * Gets the location of the specified field in the input source.
73       */
74      public InputLocation getLocation(Object key) {
75          return locations != null ? locations.get(key) : null;
76      }
77  
78      /**
79       * Creates a new builder with this object as the basis.
80       *
81       * @return a {@code Builder}
82       */
83      @Nonnull
84      public Builder with() {
85          return newBuilder(this);
86      }
87      /**
88       * Creates a new {@code ActivationProperty} instance using the specified name.
89       *
90       * @param name the new {@code String} to use
91       * @return a {@code ActivationProperty} with the specified name
92       */
93      @Nonnull
94      public ActivationProperty withName(String name) {
95          return newBuilder(this, true).name(name).build();
96      }
97      /**
98       * Creates a new {@code ActivationProperty} instance using the specified value.
99       *
100      * @param value the new {@code String} to use
101      * @return a {@code ActivationProperty} with the specified value
102      */
103     @Nonnull
104     public ActivationProperty withValue(String value) {
105         return newBuilder(this, true).value(value).build();
106     }
107 
108     /**
109      * Creates a new {@code ActivationProperty} instance.
110      * Equivalent to {@code newInstance(true)}.
111      * @see #newInstance(boolean)
112      *
113      * @return a new {@code ActivationProperty}
114      */
115     @Nonnull
116     public static ActivationProperty newInstance() {
117         return newInstance(true);
118     }
119 
120     /**
121      * Creates a new {@code ActivationProperty} instance using default values or not.
122      * Equivalent to {@code newBuilder(withDefaults).build()}.
123      *
124      * @param withDefaults the boolean indicating whether default values should be used
125      * @return a new {@code ActivationProperty}
126      */
127     @Nonnull
128     public static ActivationProperty newInstance(boolean withDefaults) {
129         return newBuilder(withDefaults).build();
130     }
131 
132     /**
133      * Creates a new {@code ActivationProperty} builder instance.
134      * Equivalent to {@code newBuilder(true)}.
135      * @see #newBuilder(boolean)
136      *
137      * @return a new {@code Builder}
138      */
139     @Nonnull
140     public static Builder newBuilder() {
141         return newBuilder(true);
142     }
143 
144     /**
145      * Creates a new {@code ActivationProperty} builder instance using default values or not.
146      *
147      * @param withDefaults the boolean indicating whether default values should be used
148      * @return a new {@code Builder}
149      */
150     @Nonnull
151     public static Builder newBuilder(boolean withDefaults) {
152         return new Builder(withDefaults);
153     }
154 
155     /**
156      * Creates a new {@code ActivationProperty} builder instance using the specified object as a basis.
157      * Equivalent to {@code newBuilder(from, false)}.
158      *
159      * @param from the {@code ActivationProperty} instance to use as a basis
160      * @return a new {@code Builder}
161      */
162     @Nonnull
163     public static Builder newBuilder(ActivationProperty from) {
164         return newBuilder(from, false);
165     }
166 
167     /**
168      * Creates a new {@code ActivationProperty} builder instance using the specified object as a basis.
169      *
170      * @param from the {@code ActivationProperty} instance to use as a basis
171      * @param forceCopy the boolean indicating if a copy should be forced
172      * @return a new {@code Builder}
173      */
174     @Nonnull
175     public static Builder newBuilder(ActivationProperty from, boolean forceCopy) {
176         return new Builder(from, forceCopy);
177     }
178 
179     /**
180      * Builder class used to create ActivationProperty instances.
181      * @see #with()
182      * @see #newBuilder()
183      */
184     @NotThreadSafe
185     public static class Builder
186     {
187         ActivationProperty base;
188         String name;
189         String value;
190         Map<Object, InputLocation> locations;
191 
192         Builder(boolean withDefaults) {
193             if (withDefaults) {
194             }
195         }
196 
197         Builder(ActivationProperty base, boolean forceCopy) {
198             if (forceCopy) {
199                 this.name = base.name;
200                 this.value = base.value;
201                 this.locations = base.locations;
202             } else {
203                 this.base = base;
204             }
205         }
206 
207         @Nonnull
208         public Builder name(String name) {
209             this.name = name;
210             return this;
211         }
212 
213         @Nonnull
214         public Builder value(String value) {
215             this.value = value;
216             return this;
217         }
218 
219 
220         @Nonnull
221         public Builder location(Object key, InputLocation location) {
222             if (location != null) {
223                 if (!(this.locations instanceof HashMap)) {
224                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
225                 }
226                 this.locations.put(key, location);
227             }
228             return this;
229         }
230 
231         @Nonnull
232         public ActivationProperty build() {
233             if (base != null
234                     && (name == null || name == base.name)
235                     && (value == null || value == base.value)
236             ) {
237                 return base;
238             }
239             Map<Object, InputLocation> newlocs = this.locations != null ? this.locations : Collections.emptyMap();
240             Map<Object, InputLocation> oldlocs = this.base != null && this.base.locations != null ? this.base.locations : Collections.emptyMap();
241             Map<Object, InputLocation> locations = new HashMap<>();
242             locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
243             locations.put("name", newlocs.containsKey("name") ? newlocs.get("name") : oldlocs.get("name"));
244             locations.put("value", newlocs.containsKey("value") ? newlocs.get("value") : oldlocs.get("value"));
245             return new ActivationProperty(
246                 name != null ? name : (base != null ? base.name : null),
247                 value != null ? value : (base != null ? base.value : null),
248                 locations
249             );
250         }
251     }
252 
253 }