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