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