1
2
3
4
5 package org.apache.maven.api.model;
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
22 @Experimental
23 @Generated @ThreadSafe @Immutable
24 public class ActivationOS
25 implements Serializable, InputLocationTracker
26 {
27
28
29
30
31 final String name;
32
33
34
35
36 final String family;
37
38
39
40
41 final String arch;
42
43
44
45
46 final String version;
47
48 final Map<Object, InputLocation> locations;
49
50
51
52
53
54 ActivationOS(
55 String name,
56 String family,
57 String arch,
58 String version,
59 Map<Object, InputLocation> locations
60 ) {
61 this.name = name;
62 this.family = family;
63 this.arch = arch;
64 this.version = version;
65 this.locations = ImmutableCollections.copy(locations);
66 }
67
68
69
70
71
72
73
74 public String getName() {
75 return this.name;
76 }
77
78
79
80
81
82
83
84 public String getFamily() {
85 return this.family;
86 }
87
88
89
90
91
92
93
94 public String getArch() {
95 return this.arch;
96 }
97
98
99
100
101
102
103
104 public String getVersion() {
105 return this.version;
106 }
107
108
109
110
111 public InputLocation getLocation(Object key) {
112 return locations != null ? locations.get(key) : null;
113 }
114
115
116
117
118
119
120 @Nonnull
121 public Builder with() {
122 return newBuilder(this);
123 }
124
125
126
127
128
129
130 @Nonnull
131 public ActivationOS withName(String name) {
132 return newBuilder(this, true).name(name).build();
133 }
134
135
136
137
138
139
140 @Nonnull
141 public ActivationOS withFamily(String family) {
142 return newBuilder(this, true).family(family).build();
143 }
144
145
146
147
148
149
150 @Nonnull
151 public ActivationOS withArch(String arch) {
152 return newBuilder(this, true).arch(arch).build();
153 }
154
155
156
157
158
159
160 @Nonnull
161 public ActivationOS withVersion(String version) {
162 return newBuilder(this, true).version(version).build();
163 }
164
165
166
167
168
169
170
171
172 @Nonnull
173 public static ActivationOS newInstance() {
174 return newInstance(true);
175 }
176
177
178
179
180
181
182
183
184 @Nonnull
185 public static ActivationOS newInstance(boolean withDefaults) {
186 return newBuilder(withDefaults).build();
187 }
188
189
190
191
192
193
194
195
196 @Nonnull
197 public static Builder newBuilder() {
198 return newBuilder(true);
199 }
200
201
202
203
204
205
206
207 @Nonnull
208 public static Builder newBuilder(boolean withDefaults) {
209 return new Builder(withDefaults);
210 }
211
212
213
214
215
216
217
218
219 @Nonnull
220 public static Builder newBuilder(ActivationOS from) {
221 return newBuilder(from, false);
222 }
223
224
225
226
227
228
229
230
231 @Nonnull
232 public static Builder newBuilder(ActivationOS from, boolean forceCopy) {
233 return new Builder(from, forceCopy);
234 }
235
236
237
238
239
240
241 @NotThreadSafe
242 public static class Builder
243 {
244 ActivationOS base;
245 String name;
246 String family;
247 String arch;
248 String version;
249 Map<Object, InputLocation> locations;
250
251 Builder(boolean withDefaults) {
252 if (withDefaults) {
253 }
254 }
255
256 Builder(ActivationOS base, boolean forceCopy) {
257 if (forceCopy) {
258 this.name = base.name;
259 this.family = base.family;
260 this.arch = base.arch;
261 this.version = base.version;
262 this.locations = base.locations;
263 } else {
264 this.base = base;
265 }
266 }
267
268 @Nonnull
269 public Builder name(String name) {
270 this.name = name;
271 return this;
272 }
273
274 @Nonnull
275 public Builder family(String family) {
276 this.family = family;
277 return this;
278 }
279
280 @Nonnull
281 public Builder arch(String arch) {
282 this.arch = arch;
283 return this;
284 }
285
286 @Nonnull
287 public Builder version(String version) {
288 this.version = version;
289 return this;
290 }
291
292
293 @Nonnull
294 public Builder location(Object key, InputLocation location) {
295 if (location != null) {
296 if (!(this.locations instanceof HashMap)) {
297 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
298 }
299 this.locations.put(key, location);
300 }
301 return this;
302 }
303
304 @Nonnull
305 public ActivationOS build() {
306 if (base != null
307 && (name == null || name == base.name)
308 && (family == null || family == base.family)
309 && (arch == null || arch == base.arch)
310 && (version == null || version == base.version)
311 ) {
312 return base;
313 }
314 Map<Object, InputLocation> newlocs = this.locations != null ? this.locations : Collections.emptyMap();
315 Map<Object, InputLocation> oldlocs = this.base != null && this.base.locations != null ? this.base.locations : Collections.emptyMap();
316 Map<Object, InputLocation> locations = new HashMap<>();
317 locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
318 locations.put("name", newlocs.containsKey("name") ? newlocs.get("name") : oldlocs.get("name"));
319 locations.put("family", newlocs.containsKey("family") ? newlocs.get("family") : oldlocs.get("family"));
320 locations.put("arch", newlocs.containsKey("arch") ? newlocs.get("arch") : oldlocs.get("arch"));
321 locations.put("version", newlocs.containsKey("version") ? newlocs.get("version") : oldlocs.get("version"));
322 return new ActivationOS(
323 name != null ? name : (base != null ? base.name : null),
324 family != null ? family : (base != null ? base.family : null),
325 arch != null ? arch : (base != null ? base.arch : null),
326 version != null ? version : (base != null ? base.version : null),
327 locations
328 );
329 }
330 }
331
332 }