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