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