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   * This element describes all of the mailing lists associated with a project. The
28   * auto-generated site references this information.
29   */
30  @Experimental
31  @Generated @ThreadSafe @Immutable
32  public class MailingList
33      implements Serializable, InputLocationTracker
34  {
35      /**
36       * The name of the mailing list.
37       */
38      final String name;
39      /**
40       * The email address or link that can be used to subscribe to
41       * the mailing list.  If this is an email address, a
42       * {@code mailto:} link will automatically be created
43       * when the documentation is created.
44       */
45      final String subscribe;
46      /**
47       * The email address or link that can be used to unsubscribe to
48       * the mailing list.  If this is an email address, a
49       * {@code mailto:} link will automatically be created
50       * when the documentation is created.
51       */
52      final String unsubscribe;
53      /**
54       * The email address or link that can be used to post to
55       * the mailing list.  If this is an email address, a
56       * {@code mailto:} link will automatically be created
57       * when the documentation is created.
58       */
59      final String post;
60      /**
61       * The link to a URL where you can browse the mailing list archive.
62       */
63      final String archive;
64      /**
65       * The link to alternate URLs where you can browse the list archive.
66       */
67      final List<String> otherArchives;
68      /** Locations */
69      final Map<Object, InputLocation> locations;
70      /** Location tracking */
71      final InputLocation importedFrom;
72  
73      /**
74        * Constructor for this class, to be called from its subclasses and {@link Builder}.
75        * @see Builder#build()
76        */
77      protected MailingList(Builder builder) {
78          this.name = builder.name != null ? builder.name : (builder.base != null ? builder.base.name : null);
79          this.subscribe = builder.subscribe != null ? builder.subscribe : (builder.base != null ? builder.base.subscribe : null);
80          this.unsubscribe = builder.unsubscribe != null ? builder.unsubscribe : (builder.base != null ? builder.base.unsubscribe : null);
81          this.post = builder.post != null ? builder.post : (builder.base != null ? builder.base.post : null);
82          this.archive = builder.archive != null ? builder.archive : (builder.base != null ? builder.base.archive : null);
83          this.otherArchives = ImmutableCollections.copy(builder.otherArchives != null ? builder.otherArchives : (builder.base != null ? builder.base.otherArchives : null));
84          this.locations = builder.computeLocations();
85          this.importedFrom = builder.importedFrom;
86      }
87  
88      /**
89       * The name of the mailing list.
90       *
91       * @return a {@code String}
92       */
93      public String getName() {
94          return this.name;
95      }
96  
97      /**
98       * The email address or link that can be used to subscribe to
99       * the mailing list.  If this is an email address, a
100      * {@code mailto:} link will automatically be created
101      * when the documentation is created.
102      *
103      * @return a {@code String}
104      */
105     public String getSubscribe() {
106         return this.subscribe;
107     }
108 
109     /**
110      * The email address or link that can be used to unsubscribe to
111      * the mailing list.  If this is an email address, a
112      * {@code mailto:} link will automatically be created
113      * when the documentation is created.
114      *
115      * @return a {@code String}
116      */
117     public String getUnsubscribe() {
118         return this.unsubscribe;
119     }
120 
121     /**
122      * The email address or link that can be used to post to
123      * the mailing list.  If this is an email address, a
124      * {@code mailto:} link will automatically be created
125      * when the documentation is created.
126      *
127      * @return a {@code String}
128      */
129     public String getPost() {
130         return this.post;
131     }
132 
133     /**
134      * The link to a URL where you can browse the mailing list archive.
135      *
136      * @return a {@code String}
137      */
138     public String getArchive() {
139         return this.archive;
140     }
141 
142     /**
143      * The link to alternate URLs where you can browse the list archive.
144      *
145      * @return a {@code List<String>}
146      */
147     @Nonnull
148     public List<String> getOtherArchives() {
149         return this.otherArchives;
150     }
151 
152     /**
153      * Gets the location of the specified field in the input source.
154      */
155     public InputLocation getLocation(Object key) {
156         return locations.get(key);
157     }
158 
159     /**
160      * Gets the keys of the locations of the input source.
161      */
162     public Set<Object> getLocationKeys() {
163         return locations.keySet();
164     }
165 
166     protected Stream<Object> getLocationKeyStream() {
167         return locations.keySet().stream();
168     }
169 
170     /**
171      * Gets the input location that caused this model to be read.
172      */
173     public InputLocation getImportedFrom()
174     {
175         return importedFrom;
176     }
177 
178     /**
179      * Creates a new builder with this object as the basis.
180      *
181      * @return a {@code Builder}
182      */
183     @Nonnull
184     public Builder with() {
185         return newBuilder(this);
186     }
187     /**
188      * Creates a new {@code MailingList} instance using the specified name.
189      *
190      * @param name the new {@code String} to use
191      * @return a {@code MailingList} with the specified name
192      */
193     @Nonnull
194     public MailingList withName(String name) {
195         return newBuilder(this, true).name(name).build();
196     }
197     /**
198      * Creates a new {@code MailingList} instance using the specified subscribe.
199      *
200      * @param subscribe the new {@code String} to use
201      * @return a {@code MailingList} with the specified subscribe
202      */
203     @Nonnull
204     public MailingList withSubscribe(String subscribe) {
205         return newBuilder(this, true).subscribe(subscribe).build();
206     }
207     /**
208      * Creates a new {@code MailingList} instance using the specified unsubscribe.
209      *
210      * @param unsubscribe the new {@code String} to use
211      * @return a {@code MailingList} with the specified unsubscribe
212      */
213     @Nonnull
214     public MailingList withUnsubscribe(String unsubscribe) {
215         return newBuilder(this, true).unsubscribe(unsubscribe).build();
216     }
217     /**
218      * Creates a new {@code MailingList} instance using the specified post.
219      *
220      * @param post the new {@code String} to use
221      * @return a {@code MailingList} with the specified post
222      */
223     @Nonnull
224     public MailingList withPost(String post) {
225         return newBuilder(this, true).post(post).build();
226     }
227     /**
228      * Creates a new {@code MailingList} instance using the specified archive.
229      *
230      * @param archive the new {@code String} to use
231      * @return a {@code MailingList} with the specified archive
232      */
233     @Nonnull
234     public MailingList withArchive(String archive) {
235         return newBuilder(this, true).archive(archive).build();
236     }
237     /**
238      * Creates a new {@code MailingList} instance using the specified otherArchives.
239      *
240      * @param otherArchives the new {@code Collection<String>} to use
241      * @return a {@code MailingList} with the specified otherArchives
242      */
243     @Nonnull
244     public MailingList withOtherArchives(Collection<String> otherArchives) {
245         return newBuilder(this, true).otherArchives(otherArchives).build();
246     }
247 
248     /**
249      * Creates a new {@code MailingList} instance.
250      * Equivalent to {@code newInstance(true)}.
251      * @see #newInstance(boolean)
252      *
253      * @return a new {@code MailingList}
254      */
255     @Nonnull
256     public static MailingList newInstance() {
257         return newInstance(true);
258     }
259 
260     /**
261      * Creates a new {@code MailingList} instance using default values or not.
262      * Equivalent to {@code newBuilder(withDefaults).build()}.
263      *
264      * @param withDefaults the boolean indicating whether default values should be used
265      * @return a new {@code MailingList}
266      */
267     @Nonnull
268     public static MailingList newInstance(boolean withDefaults) {
269         return newBuilder(withDefaults).build();
270     }
271 
272     /**
273      * Creates a new {@code MailingList} builder instance.
274      * Equivalent to {@code newBuilder(true)}.
275      * @see #newBuilder(boolean)
276      *
277      * @return a new {@code Builder}
278      */
279     @Nonnull
280     public static Builder newBuilder() {
281         return newBuilder(true);
282     }
283 
284     /**
285      * Creates a new {@code MailingList} builder instance using default values or not.
286      *
287      * @param withDefaults the boolean indicating whether default values should be used
288      * @return a new {@code Builder}
289      */
290     @Nonnull
291     public static Builder newBuilder(boolean withDefaults) {
292         return new Builder(withDefaults);
293     }
294 
295     /**
296      * Creates a new {@code MailingList} builder instance using the specified object as a basis.
297      * Equivalent to {@code newBuilder(from, false)}.
298      *
299      * @param from the {@code MailingList} instance to use as a basis
300      * @return a new {@code Builder}
301      */
302     @Nonnull
303     public static Builder newBuilder(MailingList from) {
304         return newBuilder(from, false);
305     }
306 
307     /**
308      * Creates a new {@code MailingList} builder instance using the specified object as a basis.
309      *
310      * @param from the {@code MailingList} instance to use as a basis
311      * @param forceCopy the boolean indicating if a copy should be forced
312      * @return a new {@code Builder}
313      */
314     @Nonnull
315     public static Builder newBuilder(MailingList from, boolean forceCopy) {
316         return new Builder(from, forceCopy);
317     }
318 
319     /**
320      * Builder class used to create MailingList instances.
321      * @see #with()
322      * @see #newBuilder()
323      */
324     @NotThreadSafe
325     public static class Builder
326     {
327         MailingList base;
328         String name;
329         String subscribe;
330         String unsubscribe;
331         String post;
332         String archive;
333         Collection<String> otherArchives;
334         Map<Object, InputLocation> locations;
335         InputLocation importedFrom;
336 
337         protected Builder(boolean withDefaults) {
338             if (withDefaults) {
339             }
340         }
341 
342         protected Builder(MailingList base, boolean forceCopy) {
343             if (forceCopy) {
344                 this.name = base.name;
345                 this.subscribe = base.subscribe;
346                 this.unsubscribe = base.unsubscribe;
347                 this.post = base.post;
348                 this.archive = base.archive;
349                 this.otherArchives = base.otherArchives;
350                 this.locations = base.locations;
351                 this.importedFrom = base.importedFrom;
352             } else {
353                 this.base = base;
354             }
355         }
356 
357         @Nonnull
358         public Builder name(String name) {
359             this.name = name;
360             return this;
361         }
362 
363         @Nonnull
364         public Builder subscribe(String subscribe) {
365             this.subscribe = subscribe;
366             return this;
367         }
368 
369         @Nonnull
370         public Builder unsubscribe(String unsubscribe) {
371             this.unsubscribe = unsubscribe;
372             return this;
373         }
374 
375         @Nonnull
376         public Builder post(String post) {
377             this.post = post;
378             return this;
379         }
380 
381         @Nonnull
382         public Builder archive(String archive) {
383             this.archive = archive;
384             return this;
385         }
386 
387         @Nonnull
388         public Builder otherArchives(Collection<String> otherArchives) {
389             this.otherArchives = otherArchives;
390             return this;
391         }
392 
393 
394         @Nonnull
395         public Builder location(Object key, InputLocation location) {
396             if (location != null) {
397                 if (!(this.locations instanceof HashMap)) {
398                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
399                 }
400                 this.locations.put(key, location);
401             }
402             return this;
403         }
404 
405         @Nonnull
406         public Builder importedFrom(InputLocation importedFrom) {
407             this.importedFrom = importedFrom;
408             return this;
409         }
410 
411         @Nonnull
412         public MailingList build() {
413             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
414             if (base != null
415                     && (name == null || name == base.name)
416                     && (subscribe == null || subscribe == base.subscribe)
417                     && (unsubscribe == null || unsubscribe == base.unsubscribe)
418                     && (post == null || post == base.post)
419                     && (archive == null || archive == base.archive)
420                     && (otherArchives == null || otherArchives == base.otherArchives)
421             ) {
422                 return base;
423             }
424             return new MailingList(this);
425         }
426 
427         Map<Object, InputLocation> computeLocations() {
428             Map<Object, InputLocation> newlocs = locations != null ? locations : Map.of();
429             Map<Object, InputLocation> oldlocs = base != null ? base.locations : Map.of();
430             if (newlocs.isEmpty()) {
431                 return Map.copyOf(oldlocs);
432             }
433             if (oldlocs.isEmpty()) {
434                 return Map.copyOf(newlocs);
435             }
436             return Stream.concat(newlocs.entrySet().stream(), oldlocs.entrySet().stream())
437                     // Keep value from newlocs in case of duplicates
438                     .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v1));
439         }
440     }
441 
442 
443             
444     /**
445      * @see java.lang.Object#toString()
446      */
447     public String toString()
448     {
449         return "MailingList {name=" + getName() + ", archive=" + getArchive() + "}";
450     }
451             
452           
453 }