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.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.Set;
12 import org.apache.maven.api.annotations.Experimental;
13 import org.apache.maven.api.annotations.Generated;
14 import org.apache.maven.api.annotations.Immutable;
15 import org.apache.maven.api.annotations.Nonnull;
16 import org.apache.maven.api.annotations.NotThreadSafe;
17 import org.apache.maven.api.annotations.ThreadSafe;
18
19 /**
20 * Snapshot data for the last artifact corresponding to the SNAPSHOT base version
21 */
22 @Experimental
23 @Generated @ThreadSafe @Immutable
24 public class Snapshot
25 implements Serializable
26 {
27 /**
28 * The timestamp when this version was deployed. The timestamp is expressed using UTC in the format yyyyMMdd.HHmmss.
29 */
30 final String timestamp;
31 /**
32 * The incremental build number
33 */
34 final int buildNumber;
35 /**
36 * Whether to use a local copy instead (with filename that includes the base version)
37 */
38 final boolean localCopy;
39
40 /**
41 * Constructor for this class, to be called from its subclasses and {@link Builder}.
42 * @see Builder#build()
43 */
44 protected Snapshot(Builder builder) {
45 this.timestamp = builder.timestamp != null ? builder.timestamp : (builder.base != null ? builder.base.timestamp : null);
46 this.buildNumber = builder.buildNumber != null ? builder.buildNumber : (builder.base != null ? builder.base.buildNumber : 0);
47 this.localCopy = builder.localCopy != null ? builder.localCopy : (builder.base != null ? builder.base.localCopy : false);
48 }
49
50 /**
51 * The timestamp when this version was deployed. The timestamp is expressed using UTC in the format yyyyMMdd.HHmmss.
52 *
53 * @return a {@code String}
54 */
55 public String getTimestamp() {
56 return this.timestamp;
57 }
58
59 /**
60 * The incremental build number
61 *
62 * @return a {@code int}
63 */
64 public int getBuildNumber() {
65 return this.buildNumber;
66 }
67
68 /**
69 * Whether to use a local copy instead (with filename that includes the base version)
70 *
71 * @return a {@code boolean}
72 */
73 public boolean isLocalCopy() {
74 return this.localCopy;
75 }
76
77 /**
78 * Creates a new builder with this object as the basis.
79 *
80 * @return a {@code Builder}
81 */
82 @Nonnull
83 public Builder with() {
84 return newBuilder(this);
85 }
86 /**
87 * Creates a new {@code Snapshot} instance using the specified timestamp.
88 *
89 * @param timestamp the new {@code String} to use
90 * @return a {@code Snapshot} with the specified timestamp
91 */
92 @Nonnull
93 public Snapshot withTimestamp(String timestamp) {
94 return newBuilder(this, true).timestamp(timestamp).build();
95 }
96 /**
97 * Creates a new {@code Snapshot} instance using the specified buildNumber.
98 *
99 * @param buildNumber the new {@code int} to use
100 * @return a {@code Snapshot} with the specified buildNumber
101 */
102 @Nonnull
103 public Snapshot withBuildNumber(int buildNumber) {
104 return newBuilder(this, true).buildNumber(buildNumber).build();
105 }
106 /**
107 * Creates a new {@code Snapshot} instance using the specified localCopy.
108 *
109 * @param localCopy the new {@code boolean} to use
110 * @return a {@code Snapshot} with the specified localCopy
111 */
112 @Nonnull
113 public Snapshot withLocalCopy(boolean localCopy) {
114 return newBuilder(this, true).localCopy(localCopy).build();
115 }
116
117 /**
118 * Creates a new {@code Snapshot} instance.
119 * Equivalent to {@code newInstance(true)}.
120 * @see #newInstance(boolean)
121 *
122 * @return a new {@code Snapshot}
123 */
124 @Nonnull
125 public static Snapshot newInstance() {
126 return newInstance(true);
127 }
128
129 /**
130 * Creates a new {@code Snapshot} instance using default values or not.
131 * Equivalent to {@code newBuilder(withDefaults).build()}.
132 *
133 * @param withDefaults the boolean indicating whether default values should be used
134 * @return a new {@code Snapshot}
135 */
136 @Nonnull
137 public static Snapshot newInstance(boolean withDefaults) {
138 return newBuilder(withDefaults).build();
139 }
140
141 /**
142 * Creates a new {@code Snapshot} builder instance.
143 * Equivalent to {@code newBuilder(true)}.
144 * @see #newBuilder(boolean)
145 *
146 * @return a new {@code Builder}
147 */
148 @Nonnull
149 public static Builder newBuilder() {
150 return newBuilder(true);
151 }
152
153 /**
154 * Creates a new {@code Snapshot} builder instance using default values or not.
155 *
156 * @param withDefaults the boolean indicating whether default values should be used
157 * @return a new {@code Builder}
158 */
159 @Nonnull
160 public static Builder newBuilder(boolean withDefaults) {
161 return new Builder(withDefaults);
162 }
163
164 /**
165 * Creates a new {@code Snapshot} builder instance using the specified object as a basis.
166 * Equivalent to {@code newBuilder(from, false)}.
167 *
168 * @param from the {@code Snapshot} instance to use as a basis
169 * @return a new {@code Builder}
170 */
171 @Nonnull
172 public static Builder newBuilder(Snapshot from) {
173 return newBuilder(from, false);
174 }
175
176 /**
177 * Creates a new {@code Snapshot} builder instance using the specified object as a basis.
178 *
179 * @param from the {@code Snapshot} instance to use as a basis
180 * @param forceCopy the boolean indicating if a copy should be forced
181 * @return a new {@code Builder}
182 */
183 @Nonnull
184 public static Builder newBuilder(Snapshot from, boolean forceCopy) {
185 return new Builder(from, forceCopy);
186 }
187
188 /**
189 * Builder class used to create Snapshot instances.
190 * @see #with()
191 * @see #newBuilder()
192 */
193 @NotThreadSafe
194 public static class Builder
195 {
196 Snapshot base;
197 String timestamp;
198 Integer buildNumber;
199 Boolean localCopy;
200
201 protected Builder(boolean withDefaults) {
202 if (withDefaults) {
203 this.buildNumber = 0;
204 this.localCopy = false;
205 }
206 }
207
208 protected Builder(Snapshot base, boolean forceCopy) {
209 if (forceCopy) {
210 this.timestamp = base.timestamp;
211 this.buildNumber = base.buildNumber;
212 this.localCopy = base.localCopy;
213 } else {
214 this.base = base;
215 }
216 }
217
218 @Nonnull
219 public Builder timestamp(String timestamp) {
220 this.timestamp = timestamp;
221 return this;
222 }
223
224 @Nonnull
225 public Builder buildNumber(int buildNumber) {
226 this.buildNumber = buildNumber;
227 return this;
228 }
229
230 @Nonnull
231 public Builder localCopy(boolean localCopy) {
232 this.localCopy = localCopy;
233 return this;
234 }
235
236
237 @Nonnull
238 public Snapshot build() {
239 // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
240 if (base != null
241 && (timestamp == null || timestamp == base.timestamp)
242 && (buildNumber == null || buildNumber == base.buildNumber)
243 && (localCopy == null || localCopy == base.localCopy)
244 ) {
245 return base;
246 }
247 return new Snapshot(this);
248 }
249 }
250
251 }