1 // =================== DO NOT EDIT THIS FILE ====================
2 // Generated by Modello Velocity from model.vm
3 // template, any modifications will be overwritten.
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 * Snapshot data for the last artifact corresponding to the SNAPSHOT base version
20 */
21 @Experimental
22 @Generated @ThreadSafe @Immutable
23 public class Snapshot
24 implements Serializable
25 {
26 /**
27 * The timestamp when this version was deployed. The timestamp is expressed using UTC in the format yyyyMMdd.HHmmss.
28 */
29 final String timestamp;
30 /**
31 * The incremental build number
32 */
33 final int buildNumber;
34 /**
35 * Whether to use a local copy instead (with filename that includes the base version)
36 */
37 final boolean localCopy;
38
39 /**
40 * Constructor for this class, package protected.
41 * @see Builder#build()
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 * The timestamp when this version was deployed. The timestamp is expressed using UTC in the format yyyyMMdd.HHmmss.
55 *
56 * @return a {@code String}
57 */
58 public String getTimestamp() {
59 return this.timestamp;
60 }
61
62 /**
63 * The incremental build number
64 *
65 * @return a {@code int}
66 */
67 public int getBuildNumber() {
68 return this.buildNumber;
69 }
70
71 /**
72 * Whether to use a local copy instead (with filename that includes the base version)
73 *
74 * @return a {@code boolean}
75 */
76 public boolean isLocalCopy() {
77 return this.localCopy;
78 }
79
80 /**
81 * Creates a new builder with this object as the basis.
82 *
83 * @return a {@code Builder}
84 */
85 @Nonnull
86 public Builder with() {
87 return newBuilder(this);
88 }
89 /**
90 * Creates a new {@code Snapshot} instance using the specified timestamp.
91 *
92 * @param timestamp the new {@code String} to use
93 * @return a {@code Snapshot} with the specified timestamp
94 */
95 @Nonnull
96 public Snapshot withTimestamp(String timestamp) {
97 return newBuilder(this, true).timestamp(timestamp).build();
98 }
99 /**
100 * Creates a new {@code Snapshot} instance using the specified buildNumber.
101 *
102 * @param buildNumber the new {@code int} to use
103 * @return a {@code Snapshot} with the specified buildNumber
104 */
105 @Nonnull
106 public Snapshot withBuildNumber(int buildNumber) {
107 return newBuilder(this, true).buildNumber(buildNumber).build();
108 }
109 /**
110 * Creates a new {@code Snapshot} instance using the specified localCopy.
111 *
112 * @param localCopy the new {@code boolean} to use
113 * @return a {@code Snapshot} with the specified localCopy
114 */
115 @Nonnull
116 public Snapshot withLocalCopy(boolean localCopy) {
117 return newBuilder(this, true).localCopy(localCopy).build();
118 }
119
120 /**
121 * Creates a new {@code Snapshot} instance.
122 * Equivalent to {@code newInstance(true)}.
123 * @see #newInstance(boolean)
124 *
125 * @return a new {@code Snapshot}
126 */
127 @Nonnull
128 public static Snapshot newInstance() {
129 return newInstance(true);
130 }
131
132 /**
133 * Creates a new {@code Snapshot} instance using default values or not.
134 * Equivalent to {@code newBuilder(withDefaults).build()}.
135 *
136 * @param withDefaults the boolean indicating whether default values should be used
137 * @return a new {@code Snapshot}
138 */
139 @Nonnull
140 public static Snapshot newInstance(boolean withDefaults) {
141 return newBuilder(withDefaults).build();
142 }
143
144 /**
145 * Creates a new {@code Snapshot} builder instance.
146 * Equivalent to {@code newBuilder(true)}.
147 * @see #newBuilder(boolean)
148 *
149 * @return a new {@code Builder}
150 */
151 @Nonnull
152 public static Builder newBuilder() {
153 return newBuilder(true);
154 }
155
156 /**
157 * Creates a new {@code Snapshot} builder instance using default values or not.
158 *
159 * @param withDefaults the boolean indicating whether default values should be used
160 * @return a new {@code Builder}
161 */
162 @Nonnull
163 public static Builder newBuilder(boolean withDefaults) {
164 return new Builder(withDefaults);
165 }
166
167 /**
168 * Creates a new {@code Snapshot} builder instance using the specified object as a basis.
169 * Equivalent to {@code newBuilder(from, false)}.
170 *
171 * @param from the {@code Snapshot} instance to use as a basis
172 * @return a new {@code Builder}
173 */
174 @Nonnull
175 public static Builder newBuilder(Snapshot from) {
176 return newBuilder(from, false);
177 }
178
179 /**
180 * Creates a new {@code Snapshot} builder instance using the specified object as a basis.
181 *
182 * @param from the {@code Snapshot} instance to use as a basis
183 * @param forceCopy the boolean indicating if a copy should be forced
184 * @return a new {@code Builder}
185 */
186 @Nonnull
187 public static Builder newBuilder(Snapshot from, boolean forceCopy) {
188 return new Builder(from, forceCopy);
189 }
190
191 /**
192 * Builder class used to create Snapshot instances.
193 * @see #with()
194 * @see #newBuilder()
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 }