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