1
2
3
4
5 package org.apache.maven.artifact.repository.metadata.v4;
6
7 import java.io.Serializable;
8 import java.util.Collections;
9 import java.util.HashMap;
10 import java.util.Map;
11 import org.apache.maven.api.annotations.Experimental;
12 import org.apache.maven.api.annotations.Generated;
13 import org.apache.maven.api.annotations.Immutable;
14 import org.apache.maven.api.annotations.Nonnull;
15 import org.apache.maven.api.annotations.NotThreadSafe;
16 import org.apache.maven.api.annotations.ThreadSafe;
17
18
19
20
21 @Experimental
22 @Generated @ThreadSafe @Immutable
23 public class Snapshot
24 implements Serializable
25 {
26
27
28
29 final String timestamp;
30
31
32
33 final int buildNumber;
34
35
36
37 final boolean localCopy;
38
39
40
41
42
43 Snapshot(
44 String timestamp,
45 int buildNumber,
46 boolean localCopy
47 ) {
48 this.timestamp = timestamp;
49 this.buildNumber = buildNumber;
50 this.localCopy = localCopy;
51 }
52
53
54
55
56
57
58 public String getTimestamp() {
59 return this.timestamp;
60 }
61
62
63
64
65
66
67 public int getBuildNumber() {
68 return this.buildNumber;
69 }
70
71
72
73
74
75
76 public boolean isLocalCopy() {
77 return this.localCopy;
78 }
79
80
81
82
83
84
85 @Nonnull
86 public Builder with() {
87 return newBuilder(this);
88 }
89
90
91
92
93
94
95 @Nonnull
96 public Snapshot withTimestamp(String timestamp) {
97 return newBuilder(this, true).timestamp(timestamp).build();
98 }
99
100
101
102
103
104
105 @Nonnull
106 public Snapshot withBuildNumber(int buildNumber) {
107 return newBuilder(this, true).buildNumber(buildNumber).build();
108 }
109
110
111
112
113
114
115 @Nonnull
116 public Snapshot withLocalCopy(boolean localCopy) {
117 return newBuilder(this, true).localCopy(localCopy).build();
118 }
119
120
121
122
123
124
125
126
127 @Nonnull
128 public static Snapshot newInstance() {
129 return newInstance(true);
130 }
131
132
133
134
135
136
137
138
139 @Nonnull
140 public static Snapshot newInstance(boolean withDefaults) {
141 return newBuilder(withDefaults).build();
142 }
143
144
145
146
147
148
149
150
151 @Nonnull
152 public static Builder newBuilder() {
153 return newBuilder(true);
154 }
155
156
157
158
159
160
161
162 @Nonnull
163 public static Builder newBuilder(boolean withDefaults) {
164 return new Builder(withDefaults);
165 }
166
167
168
169
170
171
172
173
174 @Nonnull
175 public static Builder newBuilder(Snapshot from) {
176 return newBuilder(from, false);
177 }
178
179
180
181
182
183
184
185
186 @Nonnull
187 public static Builder newBuilder(Snapshot from, boolean forceCopy) {
188 return new Builder(from, forceCopy);
189 }
190
191
192
193
194
195
196 @NotThreadSafe
197 public static class Builder
198 {
199 Snapshot base;
200 String timestamp;
201 Integer buildNumber;
202 Boolean localCopy;
203
204 Builder(boolean withDefaults) {
205 if (withDefaults) {
206 this.buildNumber = 0;
207 this.localCopy = false;
208 }
209 }
210
211 Builder(Snapshot base, boolean forceCopy) {
212 if (forceCopy) {
213 this.timestamp = base.timestamp;
214 this.buildNumber = base.buildNumber;
215 this.localCopy = base.localCopy;
216 } else {
217 this.base = base;
218 }
219 }
220
221 @Nonnull
222 public Builder timestamp(String timestamp) {
223 this.timestamp = timestamp;
224 return this;
225 }
226
227 @Nonnull
228 public Builder buildNumber(int buildNumber) {
229 this.buildNumber = buildNumber;
230 return this;
231 }
232
233 @Nonnull
234 public Builder localCopy(boolean localCopy) {
235 this.localCopy = localCopy;
236 return this;
237 }
238
239
240 @Nonnull
241 public Snapshot build() {
242 if (base != null
243 && (timestamp == null || timestamp == base.timestamp)
244 && (buildNumber == null || buildNumber == base.buildNumber)
245 && (localCopy == null || localCopy == base.localCopy)
246 ) {
247 return base;
248 }
249 return new Snapshot(
250 timestamp != null ? timestamp : (base != null ? base.timestamp : null),
251 buildNumber != null ? buildNumber : (base != null ? base.buildNumber : 0),
252 localCopy != null ? localCopy : (base != null ? base.localCopy : false)
253 );
254 }
255 }
256
257 }