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.ArrayList;
9   import java.util.Collection;
10  import java.util.Collections;
11  import java.util.HashMap;
12  import java.util.List;
13  import java.util.Map;
14  import java.util.Set;
15  import org.apache.maven.api.annotations.Experimental;
16  import org.apache.maven.api.annotations.Generated;
17  import org.apache.maven.api.annotations.Immutable;
18  import org.apache.maven.api.annotations.Nonnull;
19  import org.apache.maven.api.annotations.NotThreadSafe;
20  import org.apache.maven.api.annotations.ThreadSafe;
21  
22  /**
23   * Versioning information for "groupId/artifactId" or "groupId/artifactId/version" SNAPSHOT
24   */
25  @Experimental
26  @Generated @ThreadSafe @Immutable
27  public class Versioning
28      implements Serializable
29  {
30      /**
31       * What the last version added to the directory is, including both releases and snapshots ("groupId/artifactId" directory only)
32       */
33      final String latest;
34      /**
35       * What the last version added to the directory is, for the releases only ("groupId/artifactId" directory only)
36       */
37      final String release;
38      /**
39       * Versions available of the artifact (both releases and snapshots) ("groupId/artifactId" directory only)
40       */
41      final List<String> versions;
42      /**
43       * When the metadata was last updated (both "groupId/artifactId" and "groupId/artifactId/version" directories). The timestamp is expressed using UTC in the format yyyyMMddHHmmss.
44       */
45      final String lastUpdated;
46      /**
47       * The current snapshot data in use for this version ("groupId/artifactId/version" only)
48       */
49      final Snapshot snapshot;
50      /**
51       * Information for each sub-artifact available in this artifact snapshot. This is only the most recent SNAPSHOT for each unique extension/classifier combination.
52       */
53      final List<SnapshotVersion> snapshotVersions;
54  
55      /**
56        * Constructor for this class, to be called from its subclasses and {@link Builder}.
57        * @see Builder#build()
58        */
59      protected Versioning(Builder builder) {
60          this.latest = builder.latest != null ? builder.latest : (builder.base != null ? builder.base.latest : null);
61          this.release = builder.release != null ? builder.release : (builder.base != null ? builder.base.release : null);
62          this.versions = ImmutableCollections.copy(builder.versions != null ? builder.versions : (builder.base != null ? builder.base.versions : null));
63          this.lastUpdated = builder.lastUpdated != null ? builder.lastUpdated : (builder.base != null ? builder.base.lastUpdated : null);
64          this.snapshot = builder.snapshot != null ? builder.snapshot : (builder.base != null ? builder.base.snapshot : null);
65          this.snapshotVersions = ImmutableCollections.copy(builder.snapshotVersions != null ? builder.snapshotVersions : (builder.base != null ? builder.base.snapshotVersions : null));
66      }
67  
68      /**
69       * What the last version added to the directory is, including both releases and snapshots ("groupId/artifactId" directory only)
70       *
71       * @return a {@code String}
72       */
73      public String getLatest() {
74          return this.latest;
75      }
76  
77      /**
78       * What the last version added to the directory is, for the releases only ("groupId/artifactId" directory only)
79       *
80       * @return a {@code String}
81       */
82      public String getRelease() {
83          return this.release;
84      }
85  
86      /**
87       * Versions available of the artifact (both releases and snapshots) ("groupId/artifactId" directory only)
88       *
89       * @return a {@code List<String>}
90       */
91      @Nonnull
92      public List<String> getVersions() {
93          return this.versions;
94      }
95  
96      /**
97       * When the metadata was last updated (both "groupId/artifactId" and "groupId/artifactId/version" directories). The timestamp is expressed using UTC in the format yyyyMMddHHmmss.
98       *
99       * @return a {@code String}
100      */
101     public String getLastUpdated() {
102         return this.lastUpdated;
103     }
104 
105     /**
106      * The current snapshot data in use for this version ("groupId/artifactId/version" only)
107      *
108      * @return a {@code Snapshot}
109      */
110     public Snapshot getSnapshot() {
111         return this.snapshot;
112     }
113 
114     /**
115      * Information for each sub-artifact available in this artifact snapshot. This is only the most recent SNAPSHOT for each unique extension/classifier combination.
116      *
117      * @return a {@code List<SnapshotVersion>}
118      */
119     @Nonnull
120     public List<SnapshotVersion> getSnapshotVersions() {
121         return this.snapshotVersions;
122     }
123 
124     /**
125      * Creates a new builder with this object as the basis.
126      *
127      * @return a {@code Builder}
128      */
129     @Nonnull
130     public Builder with() {
131         return newBuilder(this);
132     }
133     /**
134      * Creates a new {@code Versioning} instance using the specified latest.
135      *
136      * @param latest the new {@code String} to use
137      * @return a {@code Versioning} with the specified latest
138      */
139     @Nonnull
140     public Versioning withLatest(String latest) {
141         return newBuilder(this, true).latest(latest).build();
142     }
143     /**
144      * Creates a new {@code Versioning} instance using the specified release.
145      *
146      * @param release the new {@code String} to use
147      * @return a {@code Versioning} with the specified release
148      */
149     @Nonnull
150     public Versioning withRelease(String release) {
151         return newBuilder(this, true).release(release).build();
152     }
153     /**
154      * Creates a new {@code Versioning} instance using the specified versions.
155      *
156      * @param versions the new {@code Collection<String>} to use
157      * @return a {@code Versioning} with the specified versions
158      */
159     @Nonnull
160     public Versioning withVersions(Collection<String> versions) {
161         return newBuilder(this, true).versions(versions).build();
162     }
163     /**
164      * Creates a new {@code Versioning} instance using the specified lastUpdated.
165      *
166      * @param lastUpdated the new {@code String} to use
167      * @return a {@code Versioning} with the specified lastUpdated
168      */
169     @Nonnull
170     public Versioning withLastUpdated(String lastUpdated) {
171         return newBuilder(this, true).lastUpdated(lastUpdated).build();
172     }
173     /**
174      * Creates a new {@code Versioning} instance using the specified snapshot.
175      *
176      * @param snapshot the new {@code Snapshot} to use
177      * @return a {@code Versioning} with the specified snapshot
178      */
179     @Nonnull
180     public Versioning withSnapshot(Snapshot snapshot) {
181         return newBuilder(this, true).snapshot(snapshot).build();
182     }
183     /**
184      * Creates a new {@code Versioning} instance using the specified snapshotVersions.
185      *
186      * @param snapshotVersions the new {@code Collection<SnapshotVersion>} to use
187      * @return a {@code Versioning} with the specified snapshotVersions
188      */
189     @Nonnull
190     public Versioning withSnapshotVersions(Collection<SnapshotVersion> snapshotVersions) {
191         return newBuilder(this, true).snapshotVersions(snapshotVersions).build();
192     }
193 
194     /**
195      * Creates a new {@code Versioning} instance.
196      * Equivalent to {@code newInstance(true)}.
197      * @see #newInstance(boolean)
198      *
199      * @return a new {@code Versioning}
200      */
201     @Nonnull
202     public static Versioning newInstance() {
203         return newInstance(true);
204     }
205 
206     /**
207      * Creates a new {@code Versioning} instance using default values or not.
208      * Equivalent to {@code newBuilder(withDefaults).build()}.
209      *
210      * @param withDefaults the boolean indicating whether default values should be used
211      * @return a new {@code Versioning}
212      */
213     @Nonnull
214     public static Versioning newInstance(boolean withDefaults) {
215         return newBuilder(withDefaults).build();
216     }
217 
218     /**
219      * Creates a new {@code Versioning} builder instance.
220      * Equivalent to {@code newBuilder(true)}.
221      * @see #newBuilder(boolean)
222      *
223      * @return a new {@code Builder}
224      */
225     @Nonnull
226     public static Builder newBuilder() {
227         return newBuilder(true);
228     }
229 
230     /**
231      * Creates a new {@code Versioning} builder instance using default values or not.
232      *
233      * @param withDefaults the boolean indicating whether default values should be used
234      * @return a new {@code Builder}
235      */
236     @Nonnull
237     public static Builder newBuilder(boolean withDefaults) {
238         return new Builder(withDefaults);
239     }
240 
241     /**
242      * Creates a new {@code Versioning} builder instance using the specified object as a basis.
243      * Equivalent to {@code newBuilder(from, false)}.
244      *
245      * @param from the {@code Versioning} instance to use as a basis
246      * @return a new {@code Builder}
247      */
248     @Nonnull
249     public static Builder newBuilder(Versioning from) {
250         return newBuilder(from, false);
251     }
252 
253     /**
254      * Creates a new {@code Versioning} builder instance using the specified object as a basis.
255      *
256      * @param from the {@code Versioning} instance to use as a basis
257      * @param forceCopy the boolean indicating if a copy should be forced
258      * @return a new {@code Builder}
259      */
260     @Nonnull
261     public static Builder newBuilder(Versioning from, boolean forceCopy) {
262         return new Builder(from, forceCopy);
263     }
264 
265     /**
266      * Builder class used to create Versioning instances.
267      * @see #with()
268      * @see #newBuilder()
269      */
270     @NotThreadSafe
271     public static class Builder
272     {
273         Versioning base;
274         String latest;
275         String release;
276         Collection<String> versions;
277         String lastUpdated;
278         Snapshot snapshot;
279         Collection<SnapshotVersion> snapshotVersions;
280 
281         protected Builder(boolean withDefaults) {
282             if (withDefaults) {
283             }
284         }
285 
286         protected Builder(Versioning base, boolean forceCopy) {
287             if (forceCopy) {
288                 this.latest = base.latest;
289                 this.release = base.release;
290                 this.versions = base.versions;
291                 this.lastUpdated = base.lastUpdated;
292                 this.snapshot = base.snapshot;
293                 this.snapshotVersions = base.snapshotVersions;
294             } else {
295                 this.base = base;
296             }
297         }
298 
299         @Nonnull
300         public Builder latest(String latest) {
301             this.latest = latest;
302             return this;
303         }
304 
305         @Nonnull
306         public Builder release(String release) {
307             this.release = release;
308             return this;
309         }
310 
311         @Nonnull
312         public Builder versions(Collection<String> versions) {
313             this.versions = versions;
314             return this;
315         }
316 
317         @Nonnull
318         public Builder lastUpdated(String lastUpdated) {
319             this.lastUpdated = lastUpdated;
320             return this;
321         }
322 
323         @Nonnull
324         public Builder snapshot(Snapshot snapshot) {
325             this.snapshot = snapshot;
326             return this;
327         }
328 
329         @Nonnull
330         public Builder snapshotVersions(Collection<SnapshotVersion> snapshotVersions) {
331             this.snapshotVersions = snapshotVersions;
332             return this;
333         }
334 
335 
336         @Nonnull
337         public Versioning build() {
338             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
339             if (base != null
340                     && (latest == null || latest == base.latest)
341                     && (release == null || release == base.release)
342                     && (versions == null || versions == base.versions)
343                     && (lastUpdated == null || lastUpdated == base.lastUpdated)
344                     && (snapshot == null || snapshot == base.snapshot)
345                     && (snapshotVersions == null || snapshotVersions == base.snapshotVersions)
346             ) {
347                 return base;
348             }
349             return new Versioning(this);
350         }
351     }
352 
353 }