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.metadata;
6   
7   import java.io.Serializable;
8   import java.util.Collections;
9   import java.util.HashMap;
10  import java.util.Map;
11  import java.util.Objects;
12  import java.util.Set;
13  import org.apache.maven.api.annotations.Experimental;
14  import org.apache.maven.api.annotations.Generated;
15  import org.apache.maven.api.annotations.Immutable;
16  import org.apache.maven.api.annotations.Nonnull;
17  import org.apache.maven.api.annotations.NotThreadSafe;
18  import org.apache.maven.api.annotations.ThreadSafe;
19  
20  /**
21   * Versioning information for a sub-artifact of the current snapshot artifact.
22   */
23  @Experimental
24  @Generated @ThreadSafe @Immutable
25  public class SnapshotVersion
26      implements Serializable
27  {
28      /**
29       * The classifier of the sub-artifact. Each classifier and extension pair may only appear once.
30       */
31      final String classifier;
32      /**
33       * The file extension of the sub-artifact. Each classifier and extension pair may only appear once.
34       */
35      final String extension;
36      /**
37       * The resolved snapshot version of the sub-artifact.
38       */
39      final String version;
40      /**
41       * The timestamp when this version information was last updated. The timestamp is expressed using UTC in the format yyyyMMddHHmmss.
42       */
43      final String updated;
44  
45      /**
46        * Constructor for this class, to be called from its subclasses and {@link Builder}.
47        * @see Builder#build()
48        */
49      protected SnapshotVersion(Builder builder) {
50          this.classifier = builder.classifier != null ? builder.classifier : (builder.base != null ? builder.base.classifier : null);
51          this.extension = builder.extension != null ? builder.extension : (builder.base != null ? builder.base.extension : null);
52          this.version = builder.version != null ? builder.version : (builder.base != null ? builder.base.version : null);
53          this.updated = builder.updated != null ? builder.updated : (builder.base != null ? builder.base.updated : null);
54      }
55  
56      @Override
57      public boolean equals(Object o) {
58          if (this == o) {
59              return true;
60          }
61          if (o == null || !(o instanceof SnapshotVersion)) {
62              return false;
63          }
64          SnapshotVersion that = (SnapshotVersion) o;
65          return Objects.equals( this.classifier, that.classifier ) && Objects.equals( this.extension, that.extension ) && Objects.equals( this.version, that.version ) && Objects.equals( this.updated, that.updated );
66      }
67  
68      @Override
69      public int hashCode() {
70          return Objects.hash(classifier, this.extension, this.version, this.updated);
71      }
72  
73      /**
74       * The classifier of the sub-artifact. Each classifier and extension pair may only appear once.
75       *
76       * @return a {@code String}
77       */
78      public String getClassifier() {
79          return this.classifier;
80      }
81  
82      /**
83       * The file extension of the sub-artifact. Each classifier and extension pair may only appear once.
84       *
85       * @return a {@code String}
86       */
87      public String getExtension() {
88          return this.extension;
89      }
90  
91      /**
92       * The resolved snapshot version of the sub-artifact.
93       *
94       * @return a {@code String}
95       */
96      public String getVersion() {
97          return this.version;
98      }
99  
100     /**
101      * The timestamp when this version information was last updated. The timestamp is expressed using UTC in the format yyyyMMddHHmmss.
102      *
103      * @return a {@code String}
104      */
105     public String getUpdated() {
106         return this.updated;
107     }
108 
109     /**
110      * Creates a new builder with this object as the basis.
111      *
112      * @return a {@code Builder}
113      */
114     @Nonnull
115     public Builder with() {
116         return newBuilder(this);
117     }
118     /**
119      * Creates a new {@code SnapshotVersion} instance using the specified classifier.
120      *
121      * @param classifier the new {@code String} to use
122      * @return a {@code SnapshotVersion} with the specified classifier
123      */
124     @Nonnull
125     public SnapshotVersion withClassifier(String classifier) {
126         return newBuilder(this, true).classifier(classifier).build();
127     }
128     /**
129      * Creates a new {@code SnapshotVersion} instance using the specified extension.
130      *
131      * @param extension the new {@code String} to use
132      * @return a {@code SnapshotVersion} with the specified extension
133      */
134     @Nonnull
135     public SnapshotVersion withExtension(String extension) {
136         return newBuilder(this, true).extension(extension).build();
137     }
138     /**
139      * Creates a new {@code SnapshotVersion} instance using the specified version.
140      *
141      * @param version the new {@code String} to use
142      * @return a {@code SnapshotVersion} with the specified version
143      */
144     @Nonnull
145     public SnapshotVersion withVersion(String version) {
146         return newBuilder(this, true).version(version).build();
147     }
148     /**
149      * Creates a new {@code SnapshotVersion} instance using the specified updated.
150      *
151      * @param updated the new {@code String} to use
152      * @return a {@code SnapshotVersion} with the specified updated
153      */
154     @Nonnull
155     public SnapshotVersion withUpdated(String updated) {
156         return newBuilder(this, true).updated(updated).build();
157     }
158 
159     /**
160      * Creates a new {@code SnapshotVersion} instance.
161      * Equivalent to {@code newInstance(true)}.
162      * @see #newInstance(boolean)
163      *
164      * @return a new {@code SnapshotVersion}
165      */
166     @Nonnull
167     public static SnapshotVersion newInstance() {
168         return newInstance(true);
169     }
170 
171     /**
172      * Creates a new {@code SnapshotVersion} instance using default values or not.
173      * Equivalent to {@code newBuilder(withDefaults).build()}.
174      *
175      * @param withDefaults the boolean indicating whether default values should be used
176      * @return a new {@code SnapshotVersion}
177      */
178     @Nonnull
179     public static SnapshotVersion newInstance(boolean withDefaults) {
180         return newBuilder(withDefaults).build();
181     }
182 
183     /**
184      * Creates a new {@code SnapshotVersion} builder instance.
185      * Equivalent to {@code newBuilder(true)}.
186      * @see #newBuilder(boolean)
187      *
188      * @return a new {@code Builder}
189      */
190     @Nonnull
191     public static Builder newBuilder() {
192         return newBuilder(true);
193     }
194 
195     /**
196      * Creates a new {@code SnapshotVersion} builder instance using default values or not.
197      *
198      * @param withDefaults the boolean indicating whether default values should be used
199      * @return a new {@code Builder}
200      */
201     @Nonnull
202     public static Builder newBuilder(boolean withDefaults) {
203         return new Builder(withDefaults);
204     }
205 
206     /**
207      * Creates a new {@code SnapshotVersion} builder instance using the specified object as a basis.
208      * Equivalent to {@code newBuilder(from, false)}.
209      *
210      * @param from the {@code SnapshotVersion} instance to use as a basis
211      * @return a new {@code Builder}
212      */
213     @Nonnull
214     public static Builder newBuilder(SnapshotVersion from) {
215         return newBuilder(from, false);
216     }
217 
218     /**
219      * Creates a new {@code SnapshotVersion} builder instance using the specified object as a basis.
220      *
221      * @param from the {@code SnapshotVersion} instance to use as a basis
222      * @param forceCopy the boolean indicating if a copy should be forced
223      * @return a new {@code Builder}
224      */
225     @Nonnull
226     public static Builder newBuilder(SnapshotVersion from, boolean forceCopy) {
227         return new Builder(from, forceCopy);
228     }
229 
230     /**
231      * Builder class used to create SnapshotVersion instances.
232      * @see #with()
233      * @see #newBuilder()
234      */
235     @NotThreadSafe
236     public static class Builder
237     {
238         SnapshotVersion base;
239         String classifier;
240         String extension;
241         String version;
242         String updated;
243 
244         protected Builder(boolean withDefaults) {
245             if (withDefaults) {
246             }
247         }
248 
249         protected Builder(SnapshotVersion base, boolean forceCopy) {
250             if (forceCopy) {
251                 this.classifier = base.classifier;
252                 this.extension = base.extension;
253                 this.version = base.version;
254                 this.updated = base.updated;
255             } else {
256                 this.base = base;
257             }
258         }
259 
260         @Nonnull
261         public Builder classifier(String classifier) {
262             this.classifier = classifier;
263             return this;
264         }
265 
266         @Nonnull
267         public Builder extension(String extension) {
268             this.extension = extension;
269             return this;
270         }
271 
272         @Nonnull
273         public Builder version(String version) {
274             this.version = version;
275             return this;
276         }
277 
278         @Nonnull
279         public Builder updated(String updated) {
280             this.updated = updated;
281             return this;
282         }
283 
284 
285         @Nonnull
286         public SnapshotVersion build() {
287             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
288             if (base != null
289                     && (classifier == null || classifier == base.classifier)
290                     && (extension == null || extension == base.extension)
291                     && (version == null || version == base.version)
292                     && (updated == null || updated == base.updated)
293             ) {
294                 return base;
295             }
296             return new SnapshotVersion(this);
297         }
298     }
299 
300 }