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 InputLocation location;
65
66 final InputLocation nameLocation;
67
68 final InputLocation subscribeLocation;
69
70 final InputLocation unsubscribeLocation;
71
72 final InputLocation postLocation;
73
74 final InputLocation archiveLocation;
75
76 final InputLocation otherArchivesLocation;
77
78 final Map<Object, InputLocation> locations;
79
80
81
82
83
84 MailingList(
85 String name,
86 String subscribe,
87 String unsubscribe,
88 String post,
89 String archive,
90 Collection<String> otherArchives,
91 Map<Object, InputLocation> locations,
92 InputLocation location,
93 InputLocation nameLocation,
94 InputLocation subscribeLocation,
95 InputLocation unsubscribeLocation,
96 InputLocation postLocation,
97 InputLocation archiveLocation,
98 InputLocation otherArchivesLocation
99 )
100 {
101 this.name = name;
102 this.subscribe = subscribe;
103 this.unsubscribe = unsubscribe;
104 this.post = post;
105 this.archive = archive;
106 this.otherArchives = ImmutableCollections.copy( otherArchives );
107 this.locations = ImmutableCollections.copy( locations );
108 this.location = location;
109 this.nameLocation = nameLocation;
110 this.subscribeLocation = subscribeLocation;
111 this.unsubscribeLocation = unsubscribeLocation;
112 this.postLocation = postLocation;
113 this.archiveLocation = archiveLocation;
114 this.otherArchivesLocation = otherArchivesLocation;
115 }
116
117
118
119
120
121
122 public String getName()
123 {
124 return this.name;
125 }
126
127
128
129
130
131
132
133
134
135 public String getSubscribe()
136 {
137 return this.subscribe;
138 }
139
140
141
142
143
144
145
146
147
148 public String getUnsubscribe()
149 {
150 return this.unsubscribe;
151 }
152
153
154
155
156
157
158
159
160
161 public String getPost()
162 {
163 return this.post;
164 }
165
166
167
168
169
170
171 public String getArchive()
172 {
173 return this.archive;
174 }
175
176
177
178
179
180
181 @Nonnull
182 public List<String> getOtherArchives()
183 {
184 return this.otherArchives;
185 }
186
187
188
189
190 public InputLocation getLocation( Object key )
191 {
192 if ( key instanceof String )
193 {
194 switch ( ( String ) key )
195 {
196 case "":
197 return location;
198 case "name":
199 return nameLocation;
200 case "subscribe":
201 return subscribeLocation;
202 case "unsubscribe":
203 return unsubscribeLocation;
204 case "post":
205 return postLocation;
206 case "archive":
207 return archiveLocation;
208 case "otherArchives":
209 return otherArchivesLocation;
210 }
211 }
212 return locations != null ? locations.get( key ) : null;
213 }
214
215
216
217
218
219
220 @Nonnull
221 public Builder with()
222 {
223 return newBuilder( this );
224 }
225
226
227
228
229
230
231 @Nonnull
232 public MailingList withName( String name )
233 {
234 return with().name( name ).build();
235 }
236
237
238
239
240
241
242 @Nonnull
243 public MailingList withSubscribe( String subscribe )
244 {
245 return with().subscribe( subscribe ).build();
246 }
247
248
249
250
251
252
253 @Nonnull
254 public MailingList withUnsubscribe( String unsubscribe )
255 {
256 return with().unsubscribe( unsubscribe ).build();
257 }
258
259
260
261
262
263
264 @Nonnull
265 public MailingList withPost( String post )
266 {
267 return with().post( post ).build();
268 }
269
270
271
272
273
274
275 @Nonnull
276 public MailingList withArchive( String archive )
277 {
278 return with().archive( archive ).build();
279 }
280
281
282
283
284
285
286 @Nonnull
287 public MailingList withOtherArchives( Collection<String> otherArchives )
288 {
289 return with().otherArchives( otherArchives ).build();
290 }
291
292
293
294
295
296
297
298
299 @Nonnull
300 public static MailingList newInstance()
301 {
302 return newInstance( true );
303 }
304
305
306
307
308
309
310
311
312 @Nonnull
313 public static MailingList newInstance( boolean withDefaults )
314 {
315 return newBuilder( withDefaults ).build();
316 }
317
318
319
320
321
322
323
324
325 @Nonnull
326 public static Builder newBuilder()
327 {
328 return newBuilder( true );
329 }
330
331
332
333
334
335
336
337 @Nonnull
338 public static Builder newBuilder( boolean withDefaults )
339 {
340 return new Builder( withDefaults );
341 }
342
343
344
345
346
347
348
349
350 @Nonnull
351 public static Builder newBuilder( MailingList from )
352 {
353 return newBuilder( from, false );
354 }
355
356
357
358
359
360
361
362
363 @Nonnull
364 public static Builder newBuilder( MailingList from, boolean forceCopy )
365 {
366 return new Builder( from, forceCopy );
367 }
368
369
370
371
372
373
374 @NotThreadSafe
375 public static class Builder
376 {
377 MailingList base;
378 String name;
379 String subscribe;
380 String unsubscribe;
381 String post;
382 String archive;
383 Collection<String> otherArchives;
384 Map<Object, InputLocation> locations;
385
386 Builder( boolean withDefaults )
387 {
388 if ( withDefaults )
389 {
390 }
391 }
392
393 Builder( MailingList base, boolean forceCopy )
394 {
395 if ( forceCopy )
396 {
397 this.name = base.name;
398 this.subscribe = base.subscribe;
399 this.unsubscribe = base.unsubscribe;
400 this.post = base.post;
401 this.archive = base.archive;
402 this.otherArchives = base.otherArchives;
403 }
404 else
405 {
406 this.base = base;
407 }
408 }
409
410 @Nonnull
411 public Builder name( String name )
412 {
413 this.name = name;
414 return this;
415 }
416
417 @Nonnull
418 public Builder subscribe( String subscribe )
419 {
420 this.subscribe = subscribe;
421 return this;
422 }
423
424 @Nonnull
425 public Builder unsubscribe( String unsubscribe )
426 {
427 this.unsubscribe = unsubscribe;
428 return this;
429 }
430
431 @Nonnull
432 public Builder post( String post )
433 {
434 this.post = post;
435 return this;
436 }
437
438 @Nonnull
439 public Builder archive( String archive )
440 {
441 this.archive = archive;
442 return this;
443 }
444
445 @Nonnull
446 public Builder otherArchives( Collection<String> otherArchives )
447 {
448 this.otherArchives = otherArchives;
449 return this;
450 }
451
452
453 @Nonnull
454 public Builder location( Object key, InputLocation location )
455 {
456 if ( location != null )
457 {
458 if ( this.locations == null )
459 {
460 this.locations = new HashMap<>();
461 }
462 this.locations.put( key, location );
463 }
464 return this;
465 }
466
467 @Nonnull
468 public MailingList build()
469 {
470 if ( base != null
471 && ( name == null || name == base.name )
472 && ( subscribe == null || subscribe == base.subscribe )
473 && ( unsubscribe == null || unsubscribe == base.unsubscribe )
474 && ( post == null || post == base.post )
475 && ( archive == null || archive == base.archive )
476 && ( otherArchives == null || otherArchives == base.otherArchives )
477 )
478 {
479 return base;
480 }
481 Map<Object, InputLocation> locations = null;
482 InputLocation location = null;
483 InputLocation nameLocation = null;
484 InputLocation subscribeLocation = null;
485 InputLocation unsubscribeLocation = null;
486 InputLocation postLocation = null;
487 InputLocation archiveLocation = null;
488 InputLocation otherArchivesLocation = null;
489 if ( this.locations != null )
490 {
491 locations = this.locations;
492 location = locations.remove( "" );
493 nameLocation = locations.remove( "name" );
494 subscribeLocation = locations.remove( "subscribe" );
495 unsubscribeLocation = locations.remove( "unsubscribe" );
496 postLocation = locations.remove( "post" );
497 archiveLocation = locations.remove( "archive" );
498 otherArchivesLocation = locations.remove( "otherArchives" );
499 }
500 return new MailingList(
501 name != null ? name : ( base != null ? base.name : null ),
502 subscribe != null ? subscribe : ( base != null ? base.subscribe : null ),
503 unsubscribe != null ? unsubscribe : ( base != null ? base.unsubscribe : null ),
504 post != null ? post : ( base != null ? base.post : null ),
505 archive != null ? archive : ( base != null ? base.archive : null ),
506 otherArchives != null ? otherArchives : ( base != null ? base.otherArchives : null ),
507 locations != null ? locations : ( base != null ? base.locations : null ),
508 location != null ? location : ( base != null ? base.location : null ),
509 nameLocation != null ? nameLocation : ( base != null ? base.nameLocation : null ),
510 subscribeLocation != null ? subscribeLocation : ( base != null ? base.subscribeLocation : null ),
511 unsubscribeLocation != null ? unsubscribeLocation : ( base != null ? base.unsubscribeLocation : null ),
512 postLocation != null ? postLocation : ( base != null ? base.postLocation : null ),
513 archiveLocation != null ? archiveLocation : ( base != null ? base.archiveLocation : null ),
514 otherArchivesLocation != null ? otherArchivesLocation : ( base != null ? base.otherArchivesLocation : null )
515 );
516 }
517 }
518
519
520
521
522
523
524 public String toString()
525 {
526 return "MailingList {name=" + getName() + ", archive=" + getArchive() + "}";
527 }
528
529
530 }