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      /** Location of the xml element for the field id. */
41      final InputLocation idLocation;
42      /** Location of the xml element for the field reports. */
43      final InputLocation reportsLocation;
44  
45      /**
46        * Constructor for this class, package protected.
47        * @see Builder#build()
48        */
49      ReportSet(
50          String inherited,
51          XmlNode configuration,
52          String id,
53          Collection<String> reports,
54          Map<Object, InputLocation> locations,
55          InputLocation location,
56          InputLocation inheritedLocation,
57          InputLocation configurationLocation,
58          InputLocation idLocation,
59          InputLocation reportsLocation
60      )
61      {
62          super(
63              inherited,
64              configuration,
65              locations,
66              location,
67              inheritedLocation,
68              configurationLocation
69          );
70          this.id = id;
71          this.reports = ImmutableCollections.copy( reports );
72          this.idLocation = idLocation;
73          this.reportsLocation = reportsLocation;
74      }
75  
76      /**
77       * The unique id for this report set, to be used during POM inheritance and profile injection
78       * for merging of report sets.
79       *
80       * @return a {@code String}
81       */
82      public String getId()
83      {
84          return this.id;
85      }
86  
87      /**
88       * The list of reports from this plugin which should be generated from this set.
89       *
90       * @return a {@code List<String>}
91       */
92      @Nonnull
93      public List<String> getReports()
94      {
95          return this.reports;
96      }
97  
98      /**
99       * Gets the location of the specified field in the input source.
100      */
101     public InputLocation getLocation( Object key )
102     {
103         if ( key instanceof String )
104         {
105             switch ( ( String ) key )
106             {
107                 case "id":
108                     return idLocation;
109                 case "reports":
110                     return reportsLocation;
111             }
112         }
113         return super.getLocation( key );
114     }
115 
116     /**
117      * Creates a new builder with this object as the basis.
118      *
119      * @return a {@code Builder}
120      */
121     @Nonnull
122     public Builder with()
123     {
124         return newBuilder( this );
125     }
126     /**
127      * Creates a new {@code ReportSet} instance using the specified inherited.
128      *
129      * @param inherited the new {@code String} to use
130      * @return a {@code ReportSet} with the specified inherited
131      */
132     @Nonnull
133     public ReportSet withInherited( String inherited )
134     {
135         return with().inherited( inherited ).build();
136     }
137     /**
138      * Creates a new {@code ReportSet} instance using the specified configuration.
139      *
140      * @param configuration the new {@code XmlNode} to use
141      * @return a {@code ReportSet} with the specified configuration
142      */
143     @Nonnull
144     public ReportSet withConfiguration( XmlNode configuration )
145     {
146         return with().configuration( configuration ).build();
147     }
148     /**
149      * Creates a new {@code ReportSet} instance using the specified id.
150      *
151      * @param id the new {@code String} to use
152      * @return a {@code ReportSet} with the specified id
153      */
154     @Nonnull
155     public ReportSet withId( String id )
156     {
157         return with().id( id ).build();
158     }
159     /**
160      * Creates a new {@code ReportSet} instance using the specified reports.
161      *
162      * @param reports the new {@code Collection<String>} to use
163      * @return a {@code ReportSet} with the specified reports
164      */
165     @Nonnull
166     public ReportSet withReports( Collection<String> reports )
167     {
168         return with().reports( reports ).build();
169     }
170 
171     /**
172      * Creates a new {@code ReportSet} instance.
173      * Equivalent to {@code newInstance( true )}.
174      * @see #newInstance(boolean)
175      *
176      * @return a new {@code ReportSet}
177      */
178     @Nonnull
179     public static ReportSet newInstance()
180     {
181         return newInstance( true );
182     }
183 
184     /**
185      * Creates a new {@code ReportSet} instance using default values or not.
186      * Equivalent to {@code newBuilder( withDefaults ).build()}.
187      *
188      * @param withDefaults the boolean indicating whether default values should be used
189      * @return a new {@code ReportSet}
190      */
191     @Nonnull
192     public static ReportSet newInstance( boolean withDefaults )
193     {
194         return newBuilder( withDefaults ).build();
195     }
196 
197     /**
198      * Creates a new {@code ReportSet} builder instance.
199      * Equivalent to {@code newBuilder( true )}.
200      * @see #newBuilder(boolean)
201      *
202      * @return a new {@code Builder}
203      */
204     @Nonnull
205     public static Builder newBuilder()
206     {
207         return newBuilder( true );
208     }
209 
210     /**
211      * Creates a new {@code ReportSet} builder instance using default values or not.
212      *
213      * @param withDefaults the boolean indicating whether default values should be used
214      * @return a new {@code Builder}
215      */
216     @Nonnull
217     public static Builder newBuilder( boolean withDefaults )
218     {
219         return new Builder( withDefaults );
220     }
221 
222     /**
223      * Creates a new {@code ReportSet} builder instance using the specified object as a basis.
224      * Equivalent to {@code newBuilder( from, false )}.
225      *
226      * @param from the {@code ReportSet} instance to use as a basis
227      * @return a new {@code Builder}
228      */
229     @Nonnull
230     public static Builder newBuilder( ReportSet from )
231     {
232         return newBuilder( from, false );
233     }
234 
235     /**
236      * Creates a new {@code ReportSet} builder instance using the specified object as a basis.
237      *
238      * @param from the {@code ReportSet} instance to use as a basis
239      * @param forceCopy the boolean indicating if a copy should be forced
240      * @return a new {@code Builder}
241      */
242     @Nonnull
243     public static Builder newBuilder( ReportSet from, boolean forceCopy )
244     {
245         return new Builder( from, forceCopy );
246     }
247 
248     /**
249      * Builder class used to create ReportSet instances.
250      * @see #with()
251      * @see #newBuilder()
252      */
253     @NotThreadSafe
254     public static class Builder
255         extends ConfigurationContainer.Builder
256     {
257         ReportSet base;
258         String id;
259         Collection<String> reports;
260 
261         Builder( boolean withDefaults )
262         {
263             super( withDefaults );
264             if ( withDefaults )
265             {
266                 this.id = "default";
267             }
268         }
269 
270         Builder( ReportSet base, boolean forceCopy )
271         {
272             super( base, forceCopy );
273             if ( forceCopy )
274             {
275                 this.id = base.id;
276                 this.reports = base.reports;
277             }
278             else
279             {
280                 this.base = base;
281             }
282         }
283 
284         @Nonnull
285         public Builder inherited( String inherited )
286         {
287             this.inherited = inherited;
288             return this;
289         }
290 
291         @Nonnull
292         public Builder configuration( XmlNode configuration )
293         {
294             this.configuration = configuration;
295             return this;
296         }
297 
298         @Nonnull
299         public Builder id( String id )
300         {
301             this.id = id;
302             return this;
303         }
304 
305         @Nonnull
306         public Builder reports( Collection<String> reports )
307         {
308             this.reports = reports;
309             return this;
310         }
311 
312 
313         @Nonnull
314         public Builder location( Object key, InputLocation location )
315         {
316             if ( location != null )
317             {
318                 if ( this.locations == null )
319                 {
320                     this.locations = new HashMap<>();
321                 }
322                 this.locations.put( key, location );
323             }
324             return this;
325         }
326 
327         @Nonnull
328         public ReportSet build()
329         {
330             if ( base != null
331                     && ( inherited == null || inherited == base.inherited )
332                     && ( configuration == null || configuration == base.configuration )
333                     && ( id == null || id == base.id )
334                     && ( reports == null || reports == base.reports )
335             )
336             {
337                 return base;
338             }
339             Map<Object, InputLocation> locations = null;
340             InputLocation location = null;
341             InputLocation inheritedLocation = null;
342             InputLocation configurationLocation = null;
343             InputLocation idLocation = null;
344             InputLocation reportsLocation = null;
345             if ( this.locations != null )
346             {
347                 locations = this.locations;
348                 location = locations.remove( "" );
349                 inheritedLocation = locations.remove( "inherited" );
350                 configurationLocation = locations.remove( "configuration" );
351                 idLocation = locations.remove( "id" );
352                 reportsLocation = locations.remove( "reports" );
353             }
354             return new ReportSet(
355                 inherited != null ? inherited : ( base != null ? base.inherited : null ),
356                 configuration != null ? configuration : ( base != null ? base.configuration : null ),
357                 id != null ? id : ( base != null ? base.id : null ),
358                 reports != null ? reports : ( base != null ? base.reports : null ),
359                 locations != null ? locations : ( base != null ? base.locations : null ),
360                 location != null ? location : ( base != null ? base.location : null ),
361                 inheritedLocation != null ? inheritedLocation : ( base != null ? base.inheritedLocation : null ),
362                 configurationLocation != null ? configurationLocation : ( base != null ? base.configurationLocation : null ),
363                 idLocation != null ? idLocation : ( base != null ? base.idLocation : null ),
364                 reportsLocation != null ? reportsLocation : ( base != null ? base.reportsLocation : null )
365             );
366         }
367     }
368 
369 
370             
371     @Override
372     public String toString()
373     {
374         return getId();
375     }
376             
377           
378 }