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