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