1
2
3
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.Set;
13 import org.apache.maven.api.annotations.Experimental;
14 import org.apache.maven.api.annotations.Generated;
15 import org.apache.maven.api.annotations.Immutable;
16 import org.apache.maven.api.annotations.Nonnull;
17 import org.apache.maven.api.annotations.NotThreadSafe;
18 import org.apache.maven.api.annotations.ThreadSafe;
19
20
21
22
23 @Experimental
24 @Generated @ThreadSafe @Immutable
25 public class SnapshotVersion
26 implements Serializable
27 {
28
29
30
31 final String classifier;
32
33
34
35 final String extension;
36
37
38
39 final String version;
40
41
42
43 final String updated;
44
45
46
47
48
49 protected SnapshotVersion(Builder builder) {
50 this.classifier = builder.classifier != null ? builder.classifier : (builder.base != null ? builder.base.classifier : null);
51 this.extension = builder.extension != null ? builder.extension : (builder.base != null ? builder.base.extension : null);
52 this.version = builder.version != null ? builder.version : (builder.base != null ? builder.base.version : null);
53 this.updated = builder.updated != null ? builder.updated : (builder.base != null ? builder.base.updated : null);
54 }
55
56 @Override
57 public boolean equals(Object o) {
58 if (this == o) {
59 return true;
60 }
61 if (o == null || !(o instanceof SnapshotVersion)) {
62 return false;
63 }
64 SnapshotVersion that = (SnapshotVersion) o;
65 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 );
66 }
67
68 @Override
69 public int hashCode() {
70 return Objects.hash(classifier, this.extension, this.version, this.updated);
71 }
72
73
74
75
76
77
78 public String getClassifier() {
79 return this.classifier;
80 }
81
82
83
84
85
86
87 public String getExtension() {
88 return this.extension;
89 }
90
91
92
93
94
95
96 public String getVersion() {
97 return this.version;
98 }
99
100
101
102
103
104
105 public String getUpdated() {
106 return this.updated;
107 }
108
109
110
111
112
113
114 @Nonnull
115 public Builder with() {
116 return newBuilder(this);
117 }
118
119
120
121
122
123
124 @Nonnull
125 public SnapshotVersion withClassifier(String classifier) {
126 return newBuilder(this, true).classifier(classifier).build();
127 }
128
129
130
131
132
133
134 @Nonnull
135 public SnapshotVersion withExtension(String extension) {
136 return newBuilder(this, true).extension(extension).build();
137 }
138
139
140
141
142
143
144 @Nonnull
145 public SnapshotVersion withVersion(String version) {
146 return newBuilder(this, true).version(version).build();
147 }
148
149
150
151
152
153
154 @Nonnull
155 public SnapshotVersion withUpdated(String updated) {
156 return newBuilder(this, true).updated(updated).build();
157 }
158
159
160
161
162
163
164
165
166 @Nonnull
167 public static SnapshotVersion newInstance() {
168 return newInstance(true);
169 }
170
171
172
173
174
175
176
177
178 @Nonnull
179 public static SnapshotVersion newInstance(boolean withDefaults) {
180 return newBuilder(withDefaults).build();
181 }
182
183
184
185
186
187
188
189
190 @Nonnull
191 public static Builder newBuilder() {
192 return newBuilder(true);
193 }
194
195
196
197
198
199
200
201 @Nonnull
202 public static Builder newBuilder(boolean withDefaults) {
203 return new Builder(withDefaults);
204 }
205
206
207
208
209
210
211
212
213 @Nonnull
214 public static Builder newBuilder(SnapshotVersion from) {
215 return newBuilder(from, false);
216 }
217
218
219
220
221
222
223
224
225 @Nonnull
226 public static Builder newBuilder(SnapshotVersion from, boolean forceCopy) {
227 return new Builder(from, forceCopy);
228 }
229
230
231
232
233
234
235 @NotThreadSafe
236 public static class Builder
237 {
238 SnapshotVersion base;
239 String classifier;
240 String extension;
241 String version;
242 String updated;
243
244 protected Builder(boolean withDefaults) {
245 if (withDefaults) {
246 }
247 }
248
249 protected Builder(SnapshotVersion base, boolean forceCopy) {
250 if (forceCopy) {
251 this.classifier = base.classifier;
252 this.extension = base.extension;
253 this.version = base.version;
254 this.updated = base.updated;
255 } else {
256 this.base = base;
257 }
258 }
259
260 @Nonnull
261 public Builder classifier(String classifier) {
262 this.classifier = classifier;
263 return this;
264 }
265
266 @Nonnull
267 public Builder extension(String extension) {
268 this.extension = extension;
269 return this;
270 }
271
272 @Nonnull
273 public Builder version(String version) {
274 this.version = version;
275 return this;
276 }
277
278 @Nonnull
279 public Builder updated(String updated) {
280 this.updated = updated;
281 return this;
282 }
283
284
285 @Nonnull
286 public SnapshotVersion build() {
287
288 if (base != null
289 && (classifier == null || classifier == base.classifier)
290 && (extension == null || extension == base.extension)
291 && (version == null || version == base.version)
292 && (updated == null || updated == base.updated)
293 ) {
294 return base;
295 }
296 return new SnapshotVersion(this);
297 }
298 }
299
300 }