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