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