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