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