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