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