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