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