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