1
2
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
23
24 @Experimental
25 @Generated @ThreadSafe @Immutable
26 public class ReportSet
27 extends ConfigurationContainer
28 implements Serializable, InputLocationTracker
29 {
30
31
32
33
34 final String id;
35
36
37
38 final List<String> reports;
39
40 final InputLocation idLocation;
41
42 final InputLocation reportsLocation;
43
44
45
46
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
77
78
79
80
81 public String getId()
82 {
83 return this.id;
84 }
85
86
87
88
89
90
91 @Nonnull
92 public List<String> getReports()
93 {
94 return this.reports;
95 }
96
97
98
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
117
118
119
120 @Nonnull
121 public Builder with()
122 {
123 return newBuilder( this );
124 }
125
126
127
128
129
130
131 @Nonnull
132 public ReportSet withInherited( String inherited )
133 {
134 return with().inherited( inherited ).build();
135 }
136
137
138
139
140
141
142 @Nonnull
143 public ReportSet withConfiguration( Dom configuration )
144 {
145 return with().configuration( configuration ).build();
146 }
147
148
149
150
151
152
153 @Nonnull
154 public ReportSet withId( String id )
155 {
156 return with().id( id ).build();
157 }
158
159
160
161
162
163
164 @Nonnull
165 public ReportSet withReports( Collection<String> reports )
166 {
167 return with().reports( reports ).build();
168 }
169
170
171
172
173
174
175
176
177 @Nonnull
178 public static ReportSet newInstance()
179 {
180 return newInstance( true );
181 }
182
183
184
185
186
187
188
189
190 @Nonnull
191 public static ReportSet newInstance( boolean withDefaults )
192 {
193 return newBuilder( withDefaults ).build();
194 }
195
196
197
198
199
200
201
202
203 @Nonnull
204 public static Builder newBuilder()
205 {
206 return newBuilder( true );
207 }
208
209
210
211
212
213
214
215 @Nonnull
216 public static Builder newBuilder( boolean withDefaults )
217 {
218 return new Builder( withDefaults );
219 }
220
221
222
223
224
225
226
227
228 @Nonnull
229 public static Builder newBuilder( ReportSet from )
230 {
231 return newBuilder( from, false );
232 }
233
234
235
236
237
238
239
240
241 @Nonnull
242 public static Builder newBuilder( ReportSet from, boolean forceCopy )
243 {
244 return new Builder( from, forceCopy );
245 }
246
247
248
249
250
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 }