1
2
3
4
5 package org.apache.maven.api.model;
6
7 import java.io.Serializable;
8 import java.util.ArrayList;
9 import java.util.Collection;
10 import java.util.Collections;
11 import java.util.HashMap;
12 import java.util.List;
13 import java.util.Map;
14 import java.util.Objects;
15 import java.util.Optional;
16 import java.util.Set;
17 import java.util.stream.Collectors;
18 import java.util.stream.Stream;
19 import org.apache.maven.api.annotations.Experimental;
20 import org.apache.maven.api.annotations.Generated;
21 import org.apache.maven.api.annotations.Immutable;
22 import org.apache.maven.api.annotations.Nonnull;
23 import org.apache.maven.api.annotations.NotThreadSafe;
24 import org.apache.maven.api.annotations.ThreadSafe;
25
26
27
28
29
30 @Experimental
31 @Generated @ThreadSafe @Immutable
32 public class MailingList
33 implements Serializable, InputLocationTracker
34 {
35
36
37
38 final String name;
39
40
41
42
43
44
45 final String subscribe;
46
47
48
49
50
51
52 final String unsubscribe;
53
54
55
56
57
58
59 final String post;
60
61
62
63 final String archive;
64
65
66
67 final List<String> otherArchives;
68
69 final Map<Object, InputLocation> locations;
70
71 final InputLocation importedFrom;
72
73
74
75
76
77 protected MailingList(Builder builder) {
78 this.name = builder.name != null ? builder.name : (builder.base != null ? builder.base.name : null);
79 this.subscribe = builder.subscribe != null ? builder.subscribe : (builder.base != null ? builder.base.subscribe : null);
80 this.unsubscribe = builder.unsubscribe != null ? builder.unsubscribe : (builder.base != null ? builder.base.unsubscribe : null);
81 this.post = builder.post != null ? builder.post : (builder.base != null ? builder.base.post : null);
82 this.archive = builder.archive != null ? builder.archive : (builder.base != null ? builder.base.archive : null);
83 this.otherArchives = ImmutableCollections.copy(builder.otherArchives != null ? builder.otherArchives : (builder.base != null ? builder.base.otherArchives : null));
84 this.locations = builder.computeLocations();
85 this.importedFrom = builder.importedFrom;
86 }
87
88
89
90
91
92
93 public String getName() {
94 return this.name;
95 }
96
97
98
99
100
101
102
103
104
105 public String getSubscribe() {
106 return this.subscribe;
107 }
108
109
110
111
112
113
114
115
116
117 public String getUnsubscribe() {
118 return this.unsubscribe;
119 }
120
121
122
123
124
125
126
127
128
129 public String getPost() {
130 return this.post;
131 }
132
133
134
135
136
137
138 public String getArchive() {
139 return this.archive;
140 }
141
142
143
144
145
146
147 @Nonnull
148 public List<String> getOtherArchives() {
149 return this.otherArchives;
150 }
151
152
153
154
155 public InputLocation getLocation(Object key) {
156 return locations.get(key);
157 }
158
159
160
161
162 public Set<Object> getLocationKeys() {
163 return locations.keySet();
164 }
165
166 protected Stream<Object> getLocationKeyStream() {
167 return locations.keySet().stream();
168 }
169
170
171
172
173 public InputLocation getImportedFrom()
174 {
175 return importedFrom;
176 }
177
178
179
180
181
182
183 @Nonnull
184 public Builder with() {
185 return newBuilder(this);
186 }
187
188
189
190
191
192
193 @Nonnull
194 public MailingList withName(String name) {
195 return newBuilder(this, true).name(name).build();
196 }
197
198
199
200
201
202
203 @Nonnull
204 public MailingList withSubscribe(String subscribe) {
205 return newBuilder(this, true).subscribe(subscribe).build();
206 }
207
208
209
210
211
212
213 @Nonnull
214 public MailingList withUnsubscribe(String unsubscribe) {
215 return newBuilder(this, true).unsubscribe(unsubscribe).build();
216 }
217
218
219
220
221
222
223 @Nonnull
224 public MailingList withPost(String post) {
225 return newBuilder(this, true).post(post).build();
226 }
227
228
229
230
231
232
233 @Nonnull
234 public MailingList withArchive(String archive) {
235 return newBuilder(this, true).archive(archive).build();
236 }
237
238
239
240
241
242
243 @Nonnull
244 public MailingList withOtherArchives(Collection<String> otherArchives) {
245 return newBuilder(this, true).otherArchives(otherArchives).build();
246 }
247
248
249
250
251
252
253
254
255 @Nonnull
256 public static MailingList newInstance() {
257 return newInstance(true);
258 }
259
260
261
262
263
264
265
266
267 @Nonnull
268 public static MailingList newInstance(boolean withDefaults) {
269 return newBuilder(withDefaults).build();
270 }
271
272
273
274
275
276
277
278
279 @Nonnull
280 public static Builder newBuilder() {
281 return newBuilder(true);
282 }
283
284
285
286
287
288
289
290 @Nonnull
291 public static Builder newBuilder(boolean withDefaults) {
292 return new Builder(withDefaults);
293 }
294
295
296
297
298
299
300
301
302 @Nonnull
303 public static Builder newBuilder(MailingList from) {
304 return newBuilder(from, false);
305 }
306
307
308
309
310
311
312
313
314 @Nonnull
315 public static Builder newBuilder(MailingList from, boolean forceCopy) {
316 return new Builder(from, forceCopy);
317 }
318
319
320
321
322
323
324 @NotThreadSafe
325 public static class Builder
326 {
327 MailingList base;
328 String name;
329 String subscribe;
330 String unsubscribe;
331 String post;
332 String archive;
333 Collection<String> otherArchives;
334 Map<Object, InputLocation> locations;
335 InputLocation importedFrom;
336
337 protected Builder(boolean withDefaults) {
338 if (withDefaults) {
339 }
340 }
341
342 protected Builder(MailingList base, boolean forceCopy) {
343 if (forceCopy) {
344 this.name = base.name;
345 this.subscribe = base.subscribe;
346 this.unsubscribe = base.unsubscribe;
347 this.post = base.post;
348 this.archive = base.archive;
349 this.otherArchives = base.otherArchives;
350 this.locations = base.locations;
351 this.importedFrom = base.importedFrom;
352 } else {
353 this.base = base;
354 }
355 }
356
357 @Nonnull
358 public Builder name(String name) {
359 this.name = name;
360 return this;
361 }
362
363 @Nonnull
364 public Builder subscribe(String subscribe) {
365 this.subscribe = subscribe;
366 return this;
367 }
368
369 @Nonnull
370 public Builder unsubscribe(String unsubscribe) {
371 this.unsubscribe = unsubscribe;
372 return this;
373 }
374
375 @Nonnull
376 public Builder post(String post) {
377 this.post = post;
378 return this;
379 }
380
381 @Nonnull
382 public Builder archive(String archive) {
383 this.archive = archive;
384 return this;
385 }
386
387 @Nonnull
388 public Builder otherArchives(Collection<String> otherArchives) {
389 this.otherArchives = otherArchives;
390 return this;
391 }
392
393
394 @Nonnull
395 public Builder location(Object key, InputLocation location) {
396 if (location != null) {
397 if (!(this.locations instanceof HashMap)) {
398 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
399 }
400 this.locations.put(key, location);
401 }
402 return this;
403 }
404
405 @Nonnull
406 public Builder importedFrom(InputLocation importedFrom) {
407 this.importedFrom = importedFrom;
408 return this;
409 }
410
411 @Nonnull
412 public MailingList build() {
413
414 if (base != null
415 && (name == null || name == base.name)
416 && (subscribe == null || subscribe == base.subscribe)
417 && (unsubscribe == null || unsubscribe == base.unsubscribe)
418 && (post == null || post == base.post)
419 && (archive == null || archive == base.archive)
420 && (otherArchives == null || otherArchives == base.otherArchives)
421 ) {
422 return base;
423 }
424 return new MailingList(this);
425 }
426
427 Map<Object, InputLocation> computeLocations() {
428 Map<Object, InputLocation> newlocs = locations != null ? locations : Map.of();
429 Map<Object, InputLocation> oldlocs = base != null ? base.locations : Map.of();
430 if (newlocs.isEmpty()) {
431 return Map.copyOf(oldlocs);
432 }
433 if (oldlocs.isEmpty()) {
434 return Map.copyOf(newlocs);
435 }
436 return Stream.concat(newlocs.entrySet().stream(), oldlocs.entrySet().stream())
437
438 .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v1));
439 }
440 }
441
442
443
444
445
446
447 public String toString()
448 {
449 return "MailingList {name=" + getName() + ", archive=" + getArchive() + "}";
450 }
451
452
453 }