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 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  import org.apache.maven.api.xml.XmlNode;
21  
22  /**
23   * Represents a set of reports and configuration to be used to generate them.
24   */
25  @Experimental
26  @Generated @ThreadSafe @Immutable
27  public class ReportSet
28      extends ConfigurationContainer
29      implements Serializable, InputLocationTracker
30  {
31      /**
32       * The unique id for this report set, to be used during POM inheritance and profile injection
33       * for merging of report sets.
34       */
35      final String id;
36      /**
37       * The list of reports from this plugin which should be generated from this set.
38       */
39      final List<String> reports;
40  
41      /**
42        * Constructor for this class, package protected.
43        * @see Builder#build()
44        */
45      ReportSet(
46          String inherited,
47          XmlNode configuration,
48          String id,
49          Collection<String> reports,
50          Map<Object, InputLocation> locations
51      ) {
52          super(
53              inherited,
54              configuration,
55              locations
56          );
57          this.id = id;
58          this.reports = ImmutableCollections.copy(reports);
59      }
60  
61      /**
62       * The unique id for this report set, to be used during POM inheritance and profile injection
63       * for merging of report sets.
64       *
65       * @return a {@code String}
66       */
67      public String getId() {
68          return this.id;
69      }
70  
71      /**
72       * The list of reports from this plugin which should be generated from this set.
73       *
74       * @return a {@code List<String>}
75       */
76      @Nonnull
77      public List<String> getReports() {
78          return this.reports;
79      }
80  
81      /**
82       * Creates a new builder with this object as the basis.
83       *
84       * @return a {@code Builder}
85       */
86      @Nonnull
87      public Builder with() {
88          return newBuilder(this);
89      }
90      /**
91       * Creates a new {@code ReportSet} instance using the specified inherited.
92       *
93       * @param inherited the new {@code String} to use
94       * @return a {@code ReportSet} with the specified inherited
95       */
96      @Nonnull
97      public ReportSet withInherited(String inherited) {
98          return newBuilder(this, true).inherited(inherited).build();
99      }
100     /**
101      * Creates a new {@code ReportSet} instance using the specified configuration.
102      *
103      * @param configuration the new {@code XmlNode} to use
104      * @return a {@code ReportSet} with the specified configuration
105      */
106     @Nonnull
107     public ReportSet withConfiguration(XmlNode configuration) {
108         return newBuilder(this, true).configuration(configuration).build();
109     }
110     /**
111      * Creates a new {@code ReportSet} instance using the specified id.
112      *
113      * @param id the new {@code String} to use
114      * @return a {@code ReportSet} with the specified id
115      */
116     @Nonnull
117     public ReportSet withId(String id) {
118         return newBuilder(this, true).id(id).build();
119     }
120     /**
121      * Creates a new {@code ReportSet} instance using the specified reports.
122      *
123      * @param reports the new {@code Collection<String>} to use
124      * @return a {@code ReportSet} with the specified reports
125      */
126     @Nonnull
127     public ReportSet withReports(Collection<String> reports) {
128         return newBuilder(this, true).reports(reports).build();
129     }
130 
131     /**
132      * Creates a new {@code ReportSet} instance.
133      * Equivalent to {@code newInstance(true)}.
134      * @see #newInstance(boolean)
135      *
136      * @return a new {@code ReportSet}
137      */
138     @Nonnull
139     public static ReportSet newInstance() {
140         return newInstance(true);
141     }
142 
143     /**
144      * Creates a new {@code ReportSet} instance using default values or not.
145      * Equivalent to {@code newBuilder(withDefaults).build()}.
146      *
147      * @param withDefaults the boolean indicating whether default values should be used
148      * @return a new {@code ReportSet}
149      */
150     @Nonnull
151     public static ReportSet newInstance(boolean withDefaults) {
152         return newBuilder(withDefaults).build();
153     }
154 
155     /**
156      * Creates a new {@code ReportSet} builder instance.
157      * Equivalent to {@code newBuilder(true)}.
158      * @see #newBuilder(boolean)
159      *
160      * @return a new {@code Builder}
161      */
162     @Nonnull
163     public static Builder newBuilder() {
164         return newBuilder(true);
165     }
166 
167     /**
168      * Creates a new {@code ReportSet} builder instance using default values or not.
169      *
170      * @param withDefaults the boolean indicating whether default values should be used
171      * @return a new {@code Builder}
172      */
173     @Nonnull
174     public static Builder newBuilder(boolean withDefaults) {
175         return new Builder(withDefaults);
176     }
177 
178     /**
179      * Creates a new {@code ReportSet} builder instance using the specified object as a basis.
180      * Equivalent to {@code newBuilder(from, false)}.
181      *
182      * @param from the {@code ReportSet} instance to use as a basis
183      * @return a new {@code Builder}
184      */
185     @Nonnull
186     public static Builder newBuilder(ReportSet from) {
187         return newBuilder(from, false);
188     }
189 
190     /**
191      * Creates a new {@code ReportSet} builder instance using the specified object as a basis.
192      *
193      * @param from the {@code ReportSet} instance to use as a basis
194      * @param forceCopy the boolean indicating if a copy should be forced
195      * @return a new {@code Builder}
196      */
197     @Nonnull
198     public static Builder newBuilder(ReportSet from, boolean forceCopy) {
199         return new Builder(from, forceCopy);
200     }
201 
202     /**
203      * Builder class used to create ReportSet instances.
204      * @see #with()
205      * @see #newBuilder()
206      */
207     @NotThreadSafe
208     public static class Builder
209         extends ConfigurationContainer.Builder
210     {
211         ReportSet base;
212         String id;
213         Collection<String> reports;
214 
215         Builder(boolean withDefaults) {
216             super(withDefaults);
217             if (withDefaults) {
218                 this.id = "default";
219             }
220         }
221 
222         Builder(ReportSet base, boolean forceCopy) {
223             super(base, forceCopy);
224             if (forceCopy) {
225                 this.id = base.id;
226                 this.reports = base.reports;
227                 this.locations = base.locations;
228             } else {
229                 this.base = base;
230             }
231         }
232 
233         @Nonnull
234         public Builder inherited(String inherited) {
235             this.inherited = inherited;
236             return this;
237         }
238 
239         @Nonnull
240         public Builder configuration(XmlNode configuration) {
241             this.configuration = configuration;
242             return this;
243         }
244 
245         @Nonnull
246         public Builder id(String id) {
247             this.id = id;
248             return this;
249         }
250 
251         @Nonnull
252         public Builder reports(Collection<String> reports) {
253             this.reports = reports;
254             return this;
255         }
256 
257 
258         @Nonnull
259         public Builder location(Object key, InputLocation location) {
260             if (location != null) {
261                 if (!(this.locations instanceof HashMap)) {
262                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
263                 }
264                 this.locations.put(key, location);
265             }
266             return this;
267         }
268 
269         @Nonnull
270         public ReportSet build() {
271             if (base != null
272                     && (inherited == null || inherited == base.inherited)
273                     && (configuration == null || configuration == base.configuration)
274                     && (id == null || id == base.id)
275                     && (reports == null || reports == base.reports)
276             ) {
277                 return base;
278             }
279             Map<Object, InputLocation> newlocs = this.locations != null ? this.locations : Collections.emptyMap();
280             Map<Object, InputLocation> oldlocs = this.base != null && this.base.locations != null ? this.base.locations : Collections.emptyMap();
281             Map<Object, InputLocation> locations = new HashMap<>();
282             locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
283             locations.put("inherited", newlocs.containsKey("inherited") ? newlocs.get("inherited") : oldlocs.get("inherited"));
284             locations.put("configuration", newlocs.containsKey("configuration") ? newlocs.get("configuration") : oldlocs.get("configuration"));
285             locations.put("id", newlocs.containsKey("id") ? newlocs.get("id") : oldlocs.get("id"));
286             locations.put("reports", newlocs.containsKey("reports") ? newlocs.get("reports") : oldlocs.get("reports"));
287             return new ReportSet(
288                 inherited != null ? inherited : (base != null ? base.inherited : null),
289                 configuration != null ? configuration : (base != null ? base.configuration : null),
290                 id != null ? id : (base != null ? base.id : null),
291                 reports != null ? reports : (base != null ? base.reports : null),
292                 locations
293             );
294         }
295     }
296 
297 
298             
299     @Override
300     public String toString()
301     {
302         return getId();
303     }
304             
305           
306 }