1
2
3
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
23
24 @Experimental
25 @Generated @ThreadSafe @Immutable
26 public class Versioning
27 implements Serializable
28 {
29
30
31
32 final String latest;
33
34
35
36 final String release;
37
38
39
40 final List<String> versions;
41
42
43
44 final String lastUpdated;
45
46
47
48 final Snapshot snapshot;
49
50
51
52 final List<SnapshotVersion> snapshotVersions;
53
54
55
56
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
76
77
78
79 public String getLatest() {
80 return this.latest;
81 }
82
83
84
85
86
87
88 public String getRelease() {
89 return this.release;
90 }
91
92
93
94
95
96
97 @Nonnull
98 public List<String> getVersions() {
99 return this.versions;
100 }
101
102
103
104
105
106
107 public String getLastUpdated() {
108 return this.lastUpdated;
109 }
110
111
112
113
114
115
116 public Snapshot getSnapshot() {
117 return this.snapshot;
118 }
119
120
121
122
123
124
125 @Nonnull
126 public List<SnapshotVersion> getSnapshotVersions() {
127 return this.snapshotVersions;
128 }
129
130
131
132
133
134
135 @Nonnull
136 public Builder with() {
137 return newBuilder(this);
138 }
139
140
141
142
143
144
145 @Nonnull
146 public Versioning withLatest(String latest) {
147 return newBuilder(this, true).latest(latest).build();
148 }
149
150
151
152
153
154
155 @Nonnull
156 public Versioning withRelease(String release) {
157 return newBuilder(this, true).release(release).build();
158 }
159
160
161
162
163
164
165 @Nonnull
166 public Versioning withVersions(Collection<String> versions) {
167 return newBuilder(this, true).versions(versions).build();
168 }
169
170
171
172
173
174
175 @Nonnull
176 public Versioning withLastUpdated(String lastUpdated) {
177 return newBuilder(this, true).lastUpdated(lastUpdated).build();
178 }
179
180
181
182
183
184
185 @Nonnull
186 public Versioning withSnapshot(Snapshot snapshot) {
187 return newBuilder(this, true).snapshot(snapshot).build();
188 }
189
190
191
192
193
194
195 @Nonnull
196 public Versioning withSnapshotVersions(Collection<SnapshotVersion> snapshotVersions) {
197 return newBuilder(this, true).snapshotVersions(snapshotVersions).build();
198 }
199
200
201
202
203
204
205
206
207 @Nonnull
208 public static Versioning newInstance() {
209 return newInstance(true);
210 }
211
212
213
214
215
216
217
218
219 @Nonnull
220 public static Versioning newInstance(boolean withDefaults) {
221 return newBuilder(withDefaults).build();
222 }
223
224
225
226
227
228
229
230
231 @Nonnull
232 public static Builder newBuilder() {
233 return newBuilder(true);
234 }
235
236
237
238
239
240
241
242 @Nonnull
243 public static Builder newBuilder(boolean withDefaults) {
244 return new Builder(withDefaults);
245 }
246
247
248
249
250
251
252
253
254 @Nonnull
255 public static Builder newBuilder(Versioning from) {
256 return newBuilder(from, false);
257 }
258
259
260
261
262
263
264
265
266 @Nonnull
267 public static Builder newBuilder(Versioning from, boolean forceCopy) {
268 return new Builder(from, forceCopy);
269 }
270
271
272
273
274
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 }