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   * Describes a build extension to utilise.
19   */
20  @Experimental
21  @Generated @ThreadSafe @Immutable
22  public class Extension
23      implements Serializable, InputLocationTracker
24  {
25      /**
26       * The group ID of the extension's artifact.
27       */
28      final String groupId;
29      /**
30       * The artifact ID of the extension.
31       */
32      final String artifactId;
33      /**
34       * The version of the extension.
35       */
36      final String version;
37      /** Location of the xml element for this object. */
38      final InputLocation location;
39      /** Location of the xml element for the field groupId. */
40      final InputLocation groupIdLocation;
41      /** Location of the xml element for the field artifactId. */
42      final InputLocation artifactIdLocation;
43      /** Location of the xml element for the field version. */
44      final InputLocation versionLocation;
45      /** Other locations */
46      final Map<Object, InputLocation> locations;
47  
48      /**
49        * Constructor for this class, package protected.
50        * @see Builder#build()
51        */
52      Extension(
53          String groupId,
54          String artifactId,
55          String version,
56          Map<Object, InputLocation> locations,
57          InputLocation location,
58          InputLocation groupIdLocation,
59          InputLocation artifactIdLocation,
60          InputLocation versionLocation
61      )
62      {
63          this.groupId = groupId;
64          this.artifactId = artifactId;
65          this.version = version;
66          this.locations = ImmutableCollections.copy( locations );
67          this.location = location;
68          this.groupIdLocation = groupIdLocation;
69          this.artifactIdLocation = artifactIdLocation;
70          this.versionLocation = versionLocation;
71      }
72  
73      /**
74       * The group ID of the extension's artifact.
75       *
76       * @return a {@code String}
77       */
78      public String getGroupId()
79      {
80          return this.groupId;
81      }
82  
83      /**
84       * The artifact ID of the extension.
85       *
86       * @return a {@code String}
87       */
88      public String getArtifactId()
89      {
90          return this.artifactId;
91      }
92  
93      /**
94       * The version of the extension.
95       *
96       * @return a {@code String}
97       */
98      public String getVersion()
99      {
100         return this.version;
101     }
102 
103     /**
104      * Gets the location of the specified field in the input source.
105      */
106     public InputLocation getLocation( Object key )
107     {
108         if ( key instanceof String )
109         {
110             switch ( ( String ) key )
111             {
112                 case "":
113                     return location;
114                 case "groupId":
115                     return groupIdLocation;
116                 case "artifactId":
117                     return artifactIdLocation;
118                 case "version":
119                     return versionLocation;
120             }
121         }
122         return locations != null ? locations.get( key ) : null;
123     }
124 
125     /**
126      * Creates a new builder with this object as the basis.
127      *
128      * @return a {@code Builder}
129      */
130     @Nonnull
131     public Builder with()
132     {
133         return newBuilder( this );
134     }
135     /**
136      * Creates a new {@code Extension} instance using the specified groupId.
137      *
138      * @param groupId the new {@code String} to use
139      * @return a {@code Extension} with the specified groupId
140      */
141     @Nonnull
142     public Extension withGroupId( String groupId )
143     {
144         return with().groupId( groupId ).build();
145     }
146     /**
147      * Creates a new {@code Extension} instance using the specified artifactId.
148      *
149      * @param artifactId the new {@code String} to use
150      * @return a {@code Extension} with the specified artifactId
151      */
152     @Nonnull
153     public Extension withArtifactId( String artifactId )
154     {
155         return with().artifactId( artifactId ).build();
156     }
157     /**
158      * Creates a new {@code Extension} instance using the specified version.
159      *
160      * @param version the new {@code String} to use
161      * @return a {@code Extension} with the specified version
162      */
163     @Nonnull
164     public Extension withVersion( String version )
165     {
166         return with().version( version ).build();
167     }
168 
169     /**
170      * Creates a new {@code Extension} instance.
171      * Equivalent to {@code newInstance( true )}.
172      * @see #newInstance(boolean)
173      *
174      * @return a new {@code Extension}
175      */
176     @Nonnull
177     public static Extension newInstance()
178     {
179         return newInstance( true );
180     }
181 
182     /**
183      * Creates a new {@code Extension} instance using default values or not.
184      * Equivalent to {@code newBuilder( withDefaults ).build()}.
185      *
186      * @param withDefaults the boolean indicating whether default values should be used
187      * @return a new {@code Extension}
188      */
189     @Nonnull
190     public static Extension newInstance( boolean withDefaults )
191     {
192         return newBuilder( withDefaults ).build();
193     }
194 
195     /**
196      * Creates a new {@code Extension} builder instance.
197      * Equivalent to {@code newBuilder( true )}.
198      * @see #newBuilder(boolean)
199      *
200      * @return a new {@code Builder}
201      */
202     @Nonnull
203     public static Builder newBuilder()
204     {
205         return newBuilder( true );
206     }
207 
208     /**
209      * Creates a new {@code Extension} builder instance using default values or not.
210      *
211      * @param withDefaults the boolean indicating whether default values should be used
212      * @return a new {@code Builder}
213      */
214     @Nonnull
215     public static Builder newBuilder( boolean withDefaults )
216     {
217         return new Builder( withDefaults );
218     }
219 
220     /**
221      * Creates a new {@code Extension} builder instance using the specified object as a basis.
222      * Equivalent to {@code newBuilder( from, false )}.
223      *
224      * @param from the {@code Extension} instance to use as a basis
225      * @return a new {@code Builder}
226      */
227     @Nonnull
228     public static Builder newBuilder( Extension from )
229     {
230         return newBuilder( from, false );
231     }
232 
233     /**
234      * Creates a new {@code Extension} builder instance using the specified object as a basis.
235      *
236      * @param from the {@code Extension} instance to use as a basis
237      * @param forceCopy the boolean indicating if a copy should be forced
238      * @return a new {@code Builder}
239      */
240     @Nonnull
241     public static Builder newBuilder( Extension from, boolean forceCopy )
242     {
243         return new Builder( from, forceCopy );
244     }
245 
246     /**
247      * Builder class used to create Extension instances.
248      * @see #with()
249      * @see #newBuilder()
250      */
251     @NotThreadSafe
252     public static class Builder
253     {
254         Extension base;
255         String groupId;
256         String artifactId;
257         String version;
258         Map<Object, InputLocation> locations;
259 
260         Builder( boolean withDefaults )
261         {
262             if ( withDefaults )
263             {
264             }
265         }
266 
267         Builder( Extension base, boolean forceCopy )
268         {
269             if ( forceCopy )
270             {
271                 this.groupId = base.groupId;
272                 this.artifactId = base.artifactId;
273                 this.version = base.version;
274             }
275             else
276             {
277                 this.base = base;
278             }
279         }
280 
281         @Nonnull
282         public Builder groupId( String groupId )
283         {
284             this.groupId = groupId;
285             return this;
286         }
287 
288         @Nonnull
289         public Builder artifactId( String artifactId )
290         {
291             this.artifactId = artifactId;
292             return this;
293         }
294 
295         @Nonnull
296         public Builder version( String version )
297         {
298             this.version = version;
299             return this;
300         }
301 
302 
303         @Nonnull
304         public Builder location( Object key, InputLocation location )
305         {
306             if ( location != null )
307             {
308                 if ( this.locations == null )
309                 {
310                     this.locations = new HashMap<>();
311                 }
312                 this.locations.put( key, location );
313             }
314             return this;
315         }
316 
317         @Nonnull
318         public Extension build()
319         {
320             if ( base != null
321                     && ( groupId == null || groupId == base.groupId )
322                     && ( artifactId == null || artifactId == base.artifactId )
323                     && ( version == null || version == base.version )
324             )
325             {
326                 return base;
327             }
328             Map<Object, InputLocation> locations = null;
329             InputLocation location = null;
330             InputLocation groupIdLocation = null;
331             InputLocation artifactIdLocation = null;
332             InputLocation versionLocation = null;
333             if ( this.locations != null )
334             {
335                 locations = this.locations;
336                 location = locations.remove( "" );
337                 groupIdLocation = locations.remove( "groupId" );
338                 artifactIdLocation = locations.remove( "artifactId" );
339                 versionLocation = locations.remove( "version" );
340             }
341             return new Extension(
342                 groupId != null ? groupId : ( base != null ? base.groupId : null ),
343                 artifactId != null ? artifactId : ( base != null ? base.artifactId : null ),
344                 version != null ? version : ( base != null ? base.version : null ),
345                 locations != null ? locations : ( base != null ? base.locations : null ),
346                 location != null ? location : ( base != null ? base.location : null ),
347                 groupIdLocation != null ? groupIdLocation : ( base != null ? base.groupIdLocation : null ),
348                 artifactIdLocation != null ? artifactIdLocation : ( base != null ? base.artifactIdLocation : null ),
349                 versionLocation != null ? versionLocation : ( base != null ? base.versionLocation : null )
350             );
351         }
352     }
353 
354 
355             
356     /**
357      * @see java.lang.Object#equals(java.lang.Object)
358      */
359     public boolean equals( Object o )
360     {
361         if ( this == o )
362         {
363             return true;
364         }
365 
366         if ( !( o instanceof Extension ) )
367         {
368             return false;
369         }
370 
371         Extension e = (Extension) o;
372 
373         if ( !equal( e.getArtifactId(), getArtifactId() ) )
374         {
375             return false;
376         }
377         else if ( !equal( e.getGroupId(), getGroupId() ) )
378         {
379             return false;
380         }
381         else if ( !equal( e.getVersion(), getVersion() ) )
382         {
383             return false;
384         }
385         return true;
386     }
387 
388     private static <T> boolean equal( T obj1, T obj2 )
389     {
390         return ( obj1 != null ) ? obj1.equals( obj2 ) : obj2 == null;
391     }
392 
393     /**
394      * @see java.lang.Object#hashCode()
395      */
396     public int hashCode()
397     {
398         int result = 17;
399         result = 37 * result + ( getArtifactId() != null ? getArtifactId().hashCode() : 0 );
400         result = 37 * result + ( getGroupId() != null ? getGroupId().hashCode() : 0 );
401         result = 37 * result + ( getVersion() != null ? getVersion().hashCode() : 0 );
402         return result;
403     }
404             
405           
406 }