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