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