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.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
27 @Experimental
28 @Generated @ThreadSafe @Immutable
29 public class ActivationOS
30 implements Serializable, InputLocationTracker
31 {
32
33
34
35
36 final String name;
37
38
39
40
41 final String family;
42
43
44
45
46 final String arch;
47
48
49
50
51 final String version;
52
53 final Map<Object, InputLocation> locations;
54
55 final InputLocation importedFrom;
56
57
58
59
60
61 protected ActivationOS(Builder builder) {
62 this.name = builder.name != null ? builder.name : (builder.base != null ? builder.base.name : null);
63 this.family = builder.family != null ? builder.family : (builder.base != null ? builder.base.family : null);
64 this.arch = builder.arch != null ? builder.arch : (builder.base != null ? builder.base.arch : null);
65 this.version = builder.version != null ? builder.version : (builder.base != null ? builder.base.version : null);
66 this.locations = builder.computeLocations();
67 this.importedFrom = builder.importedFrom;
68 }
69
70
71
72
73
74
75
76 public String getName() {
77 return this.name;
78 }
79
80
81
82
83
84
85
86 public String getFamily() {
87 return this.family;
88 }
89
90
91
92
93
94
95
96 public String getArch() {
97 return this.arch;
98 }
99
100
101
102
103
104
105
106 public String getVersion() {
107 return this.version;
108 }
109
110
111
112
113 public InputLocation getLocation(Object key) {
114 return locations.get(key);
115 }
116
117
118
119
120 public Set<Object> getLocationKeys() {
121 return locations.keySet();
122 }
123
124 protected Stream<Object> getLocationKeyStream() {
125 return locations.keySet().stream();
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 Map<Object, InputLocation> computeLocations() {
348 Map<Object, InputLocation> newlocs = locations != null ? locations : Map.of();
349 Map<Object, InputLocation> oldlocs = base != null ? base.locations : Map.of();
350 if (newlocs.isEmpty()) {
351 return Map.copyOf(oldlocs);
352 }
353 if (oldlocs.isEmpty()) {
354 return Map.copyOf(newlocs);
355 }
356 return Stream.concat(newlocs.entrySet().stream(), oldlocs.entrySet().stream())
357
358 .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v1));
359 }
360 }
361
362 }