View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   //  Generated by Modello Velocity from model.vm
3   //  template, any modifications will be overwritten.
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   * Description of a person who has contributed to the project, but who does not have
24   * commit privileges. Usually, these contributions come in the form of patches submitted.
25   */
26  @Experimental
27  @Generated @ThreadSafe @Immutable
28  public class Contributor
29      implements Serializable, InputLocationTracker
30  {
31      /**
32       * The full name of the contributor.
33       */
34      final String name;
35      /**
36       * The email address of the contributor.
37       */
38      final String email;
39      /**
40       * The URL for the homepage of the contributor.
41       */
42      final String url;
43      /**
44       * The organization to which the contributor belongs.
45       */
46      final String organization;
47      /**
48       * The URL of the organization.
49       */
50      final String organizationUrl;
51      /**
52       * The roles the contributor plays in the project. Each role is described by a
53       * {@code role} element, the body of which is a role name. This can also be used to
54       * describe the contribution.
55       */
56      final List<String> roles;
57      /**
58       * The timezone the contributor is in. Typically, this is a number in the range
59       * <a href="http://en.wikipedia.org/wiki/UTC%E2%88%9212:00">-12</a> to <a href="http://en.wikipedia.org/wiki/UTC%2B14:00">+14</a>
60       * or a valid time zone id like "America/Montreal" (UTC-05:00) or "Europe/Paris" (UTC+01:00).
61       */
62      final String timezone;
63      /**
64       * Properties about the contributor, such as an instant messenger handle.
65       */
66      final Map<String, String> properties;
67      /** Locations (this potentially hides the same name field from the super class) */
68      final Map<Object, InputLocation> locations;
69      /** Location tracking */
70      final InputLocation importedFrom;
71  
72      /**
73        * Constructor for this class, to be called from its subclasses and {@link Builder}.
74        * @see Builder#build()
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      * The full name of the contributor.
103      *
104      * @return a {@code String}
105      */
106     public String getName() {
107         return this.name;
108     }
109 
110     /**
111      * The email address of the contributor.
112      *
113      * @return a {@code String}
114      */
115     public String getEmail() {
116         return this.email;
117     }
118 
119     /**
120      * The URL for the homepage of the contributor.
121      *
122      * @return a {@code String}
123      */
124     public String getUrl() {
125         return this.url;
126     }
127 
128     /**
129      * The organization to which the contributor belongs.
130      *
131      * @return a {@code String}
132      */
133     public String getOrganization() {
134         return this.organization;
135     }
136 
137     /**
138      * The URL of the organization.
139      *
140      * @return a {@code String}
141      */
142     public String getOrganizationUrl() {
143         return this.organizationUrl;
144     }
145 
146     /**
147      * The roles the contributor plays in the project. Each role is described by a
148      * {@code role} element, the body of which is a role name. This can also be used to
149      * describe the contribution.
150      *
151      * @return a {@code List<String>}
152      */
153     @Nonnull
154     public List<String> getRoles() {
155         return this.roles;
156     }
157 
158     /**
159      * The timezone the contributor is in. Typically, this is a number in the range
160      * <a href="http://en.wikipedia.org/wiki/UTC%E2%88%9212:00">-12</a> to <a href="http://en.wikipedia.org/wiki/UTC%2B14:00">+14</a>
161      * or a valid time zone id like "America/Montreal" (UTC-05:00) or "Europe/Paris" (UTC+01:00).
162      *
163      * @return a {@code String}
164      */
165     public String getTimezone() {
166         return this.timezone;
167     }
168 
169     /**
170      * Properties about the contributor, such as an instant messenger handle.
171      *
172      * @return a {@code Map<String, String>}
173      */
174     @Nonnull
175     public Map<String, String> getProperties() {
176         return this.properties;
177     }
178 
179     /**
180      * Gets the location of the specified field in the input source.
181      */
182     public InputLocation getLocation(Object key) {
183         return locations != null ? locations.get(key) : null;
184     }
185 
186     /**
187     * Gets the keys of the locations of the input source.
188     */
189     public Set<Object> getLocationKeys() {
190         return locations != null ? locations.keySet() : null;
191     }
192 
193     /**
194      * Gets the input location that caused this model to be read.
195      */
196     public InputLocation getImportedFrom()
197     {
198         return importedFrom;
199     }
200 
201     /**
202      * Creates a new builder with this object as the basis.
203      *
204      * @return a {@code Builder}
205      */
206     @Nonnull
207     public Builder with() {
208         return newBuilder(this);
209     }
210     /**
211      * Creates a new {@code Contributor} instance using the specified name.
212      *
213      * @param name the new {@code String} to use
214      * @return a {@code Contributor} with the specified name
215      */
216     @Nonnull
217     public Contributor withName(String name) {
218         return newBuilder(this, true).name(name).build();
219     }
220     /**
221      * Creates a new {@code Contributor} instance using the specified email.
222      *
223      * @param email the new {@code String} to use
224      * @return a {@code Contributor} with the specified email
225      */
226     @Nonnull
227     public Contributor withEmail(String email) {
228         return newBuilder(this, true).email(email).build();
229     }
230     /**
231      * Creates a new {@code Contributor} instance using the specified url.
232      *
233      * @param url the new {@code String} to use
234      * @return a {@code Contributor} with the specified url
235      */
236     @Nonnull
237     public Contributor withUrl(String url) {
238         return newBuilder(this, true).url(url).build();
239     }
240     /**
241      * Creates a new {@code Contributor} instance using the specified organization.
242      *
243      * @param organization the new {@code String} to use
244      * @return a {@code Contributor} with the specified organization
245      */
246     @Nonnull
247     public Contributor withOrganization(String organization) {
248         return newBuilder(this, true).organization(organization).build();
249     }
250     /**
251      * Creates a new {@code Contributor} instance using the specified organizationUrl.
252      *
253      * @param organizationUrl the new {@code String} to use
254      * @return a {@code Contributor} with the specified organizationUrl
255      */
256     @Nonnull
257     public Contributor withOrganizationUrl(String organizationUrl) {
258         return newBuilder(this, true).organizationUrl(organizationUrl).build();
259     }
260     /**
261      * Creates a new {@code Contributor} instance using the specified roles.
262      *
263      * @param roles the new {@code Collection<String>} to use
264      * @return a {@code Contributor} with the specified roles
265      */
266     @Nonnull
267     public Contributor withRoles(Collection<String> roles) {
268         return newBuilder(this, true).roles(roles).build();
269     }
270     /**
271      * Creates a new {@code Contributor} instance using the specified timezone.
272      *
273      * @param timezone the new {@code String} to use
274      * @return a {@code Contributor} with the specified timezone
275      */
276     @Nonnull
277     public Contributor withTimezone(String timezone) {
278         return newBuilder(this, true).timezone(timezone).build();
279     }
280     /**
281      * Creates a new {@code Contributor} instance using the specified properties.
282      *
283      * @param properties the new {@code Map<String, String>} to use
284      * @return a {@code Contributor} with the specified properties
285      */
286     @Nonnull
287     public Contributor withProperties(Map<String, String> properties) {
288         return newBuilder(this, true).properties(properties).build();
289     }
290 
291     /**
292      * Creates a new {@code Contributor} instance.
293      * Equivalent to {@code newInstance(true)}.
294      * @see #newInstance(boolean)
295      *
296      * @return a new {@code Contributor}
297      */
298     @Nonnull
299     public static Contributor newInstance() {
300         return newInstance(true);
301     }
302 
303     /**
304      * Creates a new {@code Contributor} instance using default values or not.
305      * Equivalent to {@code newBuilder(withDefaults).build()}.
306      *
307      * @param withDefaults the boolean indicating whether default values should be used
308      * @return a new {@code Contributor}
309      */
310     @Nonnull
311     public static Contributor newInstance(boolean withDefaults) {
312         return newBuilder(withDefaults).build();
313     }
314 
315     /**
316      * Creates a new {@code Contributor} builder instance.
317      * Equivalent to {@code newBuilder(true)}.
318      * @see #newBuilder(boolean)
319      *
320      * @return a new {@code Builder}
321      */
322     @Nonnull
323     public static Builder newBuilder() {
324         return newBuilder(true);
325     }
326 
327     /**
328      * Creates a new {@code Contributor} builder instance using default values or not.
329      *
330      * @param withDefaults the boolean indicating whether default values should be used
331      * @return a new {@code Builder}
332      */
333     @Nonnull
334     public static Builder newBuilder(boolean withDefaults) {
335         return new Builder(withDefaults);
336     }
337 
338     /**
339      * Creates a new {@code Contributor} builder instance using the specified object as a basis.
340      * Equivalent to {@code newBuilder(from, false)}.
341      *
342      * @param from the {@code Contributor} instance to use as a basis
343      * @return a new {@code Builder}
344      */
345     @Nonnull
346     public static Builder newBuilder(Contributor from) {
347         return newBuilder(from, false);
348     }
349 
350     /**
351      * Creates a new {@code Contributor} builder instance using the specified object as a basis.
352      *
353      * @param from the {@code Contributor} instance to use as a basis
354      * @param forceCopy the boolean indicating if a copy should be forced
355      * @return a new {@code Builder}
356      */
357     @Nonnull
358     public static Builder newBuilder(Contributor from, boolean forceCopy) {
359         return new Builder(from, forceCopy);
360     }
361 
362     /**
363      * Builder class used to create Contributor instances.
364      * @see #with()
365      * @see #newBuilder()
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             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
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      * @see java.lang.Object#toString()
493      */
494     public String toString()
495     {
496         return "Contributor {name=" + getName() + ", email=" + getEmail() + "}";
497     }
498             
499           
500 }