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