1
2
3
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
24
25 @Experimental
26 @Generated @ThreadSafe @Immutable
27 public class ReportSet
28 extends ConfigurationContainer
29 implements Serializable, InputLocationTracker
30 {
31
32
33
34
35 final String id;
36
37
38
39 final List<String> reports;
40
41
42
43
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
63
64
65
66
67 public String getId() {
68 return this.id;
69 }
70
71
72
73
74
75
76 @Nonnull
77 public List<String> getReports() {
78 return this.reports;
79 }
80
81
82
83
84
85
86 @Nonnull
87 public Builder with() {
88 return newBuilder(this);
89 }
90
91
92
93
94
95
96 @Nonnull
97 public ReportSet withInherited(String inherited) {
98 return newBuilder(this, true).inherited(inherited).build();
99 }
100
101
102
103
104
105
106 @Nonnull
107 public ReportSet withConfiguration(XmlNode configuration) {
108 return newBuilder(this, true).configuration(configuration).build();
109 }
110
111
112
113
114
115
116 @Nonnull
117 public ReportSet withId(String id) {
118 return newBuilder(this, true).id(id).build();
119 }
120
121
122
123
124
125
126 @Nonnull
127 public ReportSet withReports(Collection<String> reports) {
128 return newBuilder(this, true).reports(reports).build();
129 }
130
131
132
133
134
135
136
137
138 @Nonnull
139 public static ReportSet newInstance() {
140 return newInstance(true);
141 }
142
143
144
145
146
147
148
149
150 @Nonnull
151 public static ReportSet newInstance(boolean withDefaults) {
152 return newBuilder(withDefaults).build();
153 }
154
155
156
157
158
159
160
161
162 @Nonnull
163 public static Builder newBuilder() {
164 return newBuilder(true);
165 }
166
167
168
169
170
171
172
173 @Nonnull
174 public static Builder newBuilder(boolean withDefaults) {
175 return new Builder(withDefaults);
176 }
177
178
179
180
181
182
183
184
185 @Nonnull
186 public static Builder newBuilder(ReportSet from) {
187 return newBuilder(from, false);
188 }
189
190
191
192
193
194
195
196
197 @Nonnull
198 public static Builder newBuilder(ReportSet from, boolean forceCopy) {
199 return new Builder(from, forceCopy);
200 }
201
202
203
204
205
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 }