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 Contributor
28 implements Serializable, InputLocationTracker
29 {
30
31
32
33 final String name;
34
35
36
37 final String email;
38
39
40
41 final String url;
42
43
44
45 final String organization;
46
47
48
49 final String organizationUrl;
50
51
52
53
54
55 final List<String> roles;
56
57
58
59
60
61 final String timezone;
62
63
64
65 final Map<String, String> properties;
66
67 final InputLocation location;
68
69 final InputLocation nameLocation;
70
71 final InputLocation emailLocation;
72
73 final InputLocation urlLocation;
74
75 final InputLocation organizationLocation;
76
77 final InputLocation organizationUrlLocation;
78
79 final InputLocation rolesLocation;
80
81 final InputLocation timezoneLocation;
82
83 final InputLocation propertiesLocation;
84
85 final Map<Object, InputLocation> locations;
86
87
88
89
90
91 Contributor(
92 String name,
93 String email,
94 String url,
95 String organization,
96 String organizationUrl,
97 Collection<String> roles,
98 String timezone,
99 Map<String, String> properties,
100 Map<Object, InputLocation> locations,
101 InputLocation location,
102 InputLocation nameLocation,
103 InputLocation emailLocation,
104 InputLocation urlLocation,
105 InputLocation organizationLocation,
106 InputLocation organizationUrlLocation,
107 InputLocation rolesLocation,
108 InputLocation timezoneLocation,
109 InputLocation propertiesLocation
110 )
111 {
112 this.name = name;
113 this.email = email;
114 this.url = url;
115 this.organization = organization;
116 this.organizationUrl = organizationUrl;
117 this.roles = ImmutableCollections.copy( roles );
118 this.timezone = timezone;
119 this.properties = ImmutableCollections.copy( properties );
120 this.locations = ImmutableCollections.copy( locations );
121 this.location = location;
122 this.nameLocation = nameLocation;
123 this.emailLocation = emailLocation;
124 this.urlLocation = urlLocation;
125 this.organizationLocation = organizationLocation;
126 this.organizationUrlLocation = organizationUrlLocation;
127 this.rolesLocation = rolesLocation;
128 this.timezoneLocation = timezoneLocation;
129 this.propertiesLocation = propertiesLocation;
130 }
131
132
133
134
135
136
137 public String getName()
138 {
139 return this.name;
140 }
141
142
143
144
145
146
147 public String getEmail()
148 {
149 return this.email;
150 }
151
152
153
154
155
156
157 public String getUrl()
158 {
159 return this.url;
160 }
161
162
163
164
165
166
167 public String getOrganization()
168 {
169 return this.organization;
170 }
171
172
173
174
175
176
177 public String getOrganizationUrl()
178 {
179 return this.organizationUrl;
180 }
181
182
183
184
185
186
187
188
189 @Nonnull
190 public List<String> getRoles()
191 {
192 return this.roles;
193 }
194
195
196
197
198
199
200
201
202 public String getTimezone()
203 {
204 return this.timezone;
205 }
206
207
208
209
210
211
212 @Nonnull
213 public Map<String, String> getProperties()
214 {
215 return this.properties;
216 }
217
218
219
220
221 public InputLocation getLocation( Object key )
222 {
223 if ( key instanceof String )
224 {
225 switch ( ( String ) key )
226 {
227 case "":
228 return location;
229 case "name":
230 return nameLocation;
231 case "email":
232 return emailLocation;
233 case "url":
234 return urlLocation;
235 case "organization":
236 return organizationLocation;
237 case "organizationUrl":
238 return organizationUrlLocation;
239 case "roles":
240 return rolesLocation;
241 case "timezone":
242 return timezoneLocation;
243 case "properties":
244 return propertiesLocation;
245 }
246 }
247 return locations != null ? locations.get( key ) : null;
248 }
249
250
251
252
253
254
255 @Nonnull
256 public Builder with()
257 {
258 return newBuilder( this );
259 }
260
261
262
263
264
265
266 @Nonnull
267 public Contributor withName( String name )
268 {
269 return with().name( name ).build();
270 }
271
272
273
274
275
276
277 @Nonnull
278 public Contributor withEmail( String email )
279 {
280 return with().email( email ).build();
281 }
282
283
284
285
286
287
288 @Nonnull
289 public Contributor withUrl( String url )
290 {
291 return with().url( url ).build();
292 }
293
294
295
296
297
298
299 @Nonnull
300 public Contributor withOrganization( String organization )
301 {
302 return with().organization( organization ).build();
303 }
304
305
306
307
308
309
310 @Nonnull
311 public Contributor withOrganizationUrl( String organizationUrl )
312 {
313 return with().organizationUrl( organizationUrl ).build();
314 }
315
316
317
318
319
320
321 @Nonnull
322 public Contributor withRoles( Collection<String> roles )
323 {
324 return with().roles( roles ).build();
325 }
326
327
328
329
330
331
332 @Nonnull
333 public Contributor withTimezone( String timezone )
334 {
335 return with().timezone( timezone ).build();
336 }
337
338
339
340
341
342
343 @Nonnull
344 public Contributor withProperties( Map<String, String> properties )
345 {
346 return with().properties( properties ).build();
347 }
348
349
350
351
352
353
354
355
356 @Nonnull
357 public static Contributor newInstance()
358 {
359 return newInstance( true );
360 }
361
362
363
364
365
366
367
368
369 @Nonnull
370 public static Contributor newInstance( boolean withDefaults )
371 {
372 return newBuilder( withDefaults ).build();
373 }
374
375
376
377
378
379
380
381
382 @Nonnull
383 public static Builder newBuilder()
384 {
385 return newBuilder( true );
386 }
387
388
389
390
391
392
393
394 @Nonnull
395 public static Builder newBuilder( boolean withDefaults )
396 {
397 return new Builder( withDefaults );
398 }
399
400
401
402
403
404
405
406
407 @Nonnull
408 public static Builder newBuilder( Contributor from )
409 {
410 return newBuilder( from, false );
411 }
412
413
414
415
416
417
418
419
420 @Nonnull
421 public static Builder newBuilder( Contributor from, boolean forceCopy )
422 {
423 return new Builder( from, forceCopy );
424 }
425
426
427
428
429
430
431 @NotThreadSafe
432 public static class Builder
433 {
434 Contributor base;
435 String name;
436 String email;
437 String url;
438 String organization;
439 String organizationUrl;
440 Collection<String> roles;
441 String timezone;
442 Map<String, String> properties;
443 Map<Object, InputLocation> locations;
444
445 Builder( boolean withDefaults )
446 {
447 if ( withDefaults )
448 {
449 }
450 }
451
452 Builder( Contributor base, boolean forceCopy )
453 {
454 if ( forceCopy )
455 {
456 this.name = base.name;
457 this.email = base.email;
458 this.url = base.url;
459 this.organization = base.organization;
460 this.organizationUrl = base.organizationUrl;
461 this.roles = base.roles;
462 this.timezone = base.timezone;
463 this.properties = base.properties;
464 }
465 else
466 {
467 this.base = base;
468 }
469 }
470
471 @Nonnull
472 public Builder name( String name )
473 {
474 this.name = name;
475 return this;
476 }
477
478 @Nonnull
479 public Builder email( String email )
480 {
481 this.email = email;
482 return this;
483 }
484
485 @Nonnull
486 public Builder url( String url )
487 {
488 this.url = url;
489 return this;
490 }
491
492 @Nonnull
493 public Builder organization( String organization )
494 {
495 this.organization = organization;
496 return this;
497 }
498
499 @Nonnull
500 public Builder organizationUrl( String organizationUrl )
501 {
502 this.organizationUrl = organizationUrl;
503 return this;
504 }
505
506 @Nonnull
507 public Builder roles( Collection<String> roles )
508 {
509 this.roles = roles;
510 return this;
511 }
512
513 @Nonnull
514 public Builder timezone( String timezone )
515 {
516 this.timezone = timezone;
517 return this;
518 }
519
520 @Nonnull
521 public Builder properties( Map<String, String> properties )
522 {
523 this.properties = properties;
524 return this;
525 }
526
527
528 @Nonnull
529 public Builder location( Object key, InputLocation location )
530 {
531 if ( location != null )
532 {
533 if ( this.locations == null )
534 {
535 this.locations = new HashMap<>();
536 }
537 this.locations.put( key, location );
538 }
539 return this;
540 }
541
542 @Nonnull
543 public Contributor build()
544 {
545 if ( base != null
546 && ( name == null || name == base.name )
547 && ( email == null || email == base.email )
548 && ( url == null || url == base.url )
549 && ( organization == null || organization == base.organization )
550 && ( organizationUrl == null || organizationUrl == base.organizationUrl )
551 && ( roles == null || roles == base.roles )
552 && ( timezone == null || timezone == base.timezone )
553 && ( properties == null || properties == base.properties )
554 )
555 {
556 return base;
557 }
558 Map<Object, InputLocation> locations = null;
559 InputLocation location = null;
560 InputLocation nameLocation = null;
561 InputLocation emailLocation = null;
562 InputLocation urlLocation = null;
563 InputLocation organizationLocation = null;
564 InputLocation organizationUrlLocation = null;
565 InputLocation rolesLocation = null;
566 InputLocation timezoneLocation = null;
567 InputLocation propertiesLocation = null;
568 if ( this.locations != null )
569 {
570 locations = this.locations;
571 location = locations.remove( "" );
572 nameLocation = locations.remove( "name" );
573 emailLocation = locations.remove( "email" );
574 urlLocation = locations.remove( "url" );
575 organizationLocation = locations.remove( "organization" );
576 organizationUrlLocation = locations.remove( "organizationUrl" );
577 rolesLocation = locations.remove( "roles" );
578 timezoneLocation = locations.remove( "timezone" );
579 propertiesLocation = locations.remove( "properties" );
580 }
581 return new Contributor(
582 name != null ? name : ( base != null ? base.name : null ),
583 email != null ? email : ( base != null ? base.email : null ),
584 url != null ? url : ( base != null ? base.url : null ),
585 organization != null ? organization : ( base != null ? base.organization : null ),
586 organizationUrl != null ? organizationUrl : ( base != null ? base.organizationUrl : null ),
587 roles != null ? roles : ( base != null ? base.roles : null ),
588 timezone != null ? timezone : ( base != null ? base.timezone : null ),
589 properties != null ? properties : ( base != null ? base.properties : null ),
590 locations != null ? locations : ( base != null ? base.locations : null ),
591 location != null ? location : ( base != null ? base.location : null ),
592 nameLocation != null ? nameLocation : ( base != null ? base.nameLocation : null ),
593 emailLocation != null ? emailLocation : ( base != null ? base.emailLocation : null ),
594 urlLocation != null ? urlLocation : ( base != null ? base.urlLocation : null ),
595 organizationLocation != null ? organizationLocation : ( base != null ? base.organizationLocation : null ),
596 organizationUrlLocation != null ? organizationUrlLocation : ( base != null ? base.organizationUrlLocation : null ),
597 rolesLocation != null ? rolesLocation : ( base != null ? base.rolesLocation : null ),
598 timezoneLocation != null ? timezoneLocation : ( base != null ? base.timezoneLocation : null ),
599 propertiesLocation != null ? propertiesLocation : ( base != null ? base.propertiesLocation : null )
600 );
601 }
602 }
603
604
605
606
607
608
609 public String toString()
610 {
611 return "Contributor {name=" + getName() + ", email=" + getEmail() + "}";
612 }
613
614
615 }