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