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