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
22
23
24
25
26 @Experimental
27 @Generated @ThreadSafe @Immutable
28 public class CiManagement
29 implements Serializable, InputLocationTracker
30 {
31
32
33
34 final String system;
35
36
37
38 final String url;
39
40
41
42
43 final List<Notifier> notifiers;
44
45 final Map<Object, InputLocation> locations;
46
47 final InputLocation importedFrom;
48
49
50
51
52
53 protected CiManagement(Builder builder) {
54 this.system = builder.system != null ? builder.system : (builder.base != null ? builder.base.system : null);
55 this.url = builder.url != null ? builder.url : (builder.base != null ? builder.base.url : null);
56 this.notifiers = ImmutableCollections.copy(builder.notifiers != null ? builder.notifiers : (builder.base != null ? builder.base.notifiers : null));
57 Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
58 Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap();
59 Map<Object, InputLocation> mutableLocations = new HashMap<>();
60 this.importedFrom = builder.importedFrom;
61 mutableLocations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
62 mutableLocations.put("system", newlocs.containsKey("system") ? newlocs.get("system") : oldlocs.get("system"));
63 mutableLocations.put("url", newlocs.containsKey("url") ? newlocs.get("url") : oldlocs.get("url"));
64 mutableLocations.put("notifiers", newlocs.containsKey("notifiers") ? newlocs.get("notifiers") : oldlocs.get("notifiers"));
65 this.locations = Collections.unmodifiableMap(mutableLocations);
66 }
67
68
69
70
71
72
73 public String getSystem() {
74 return this.system;
75 }
76
77
78
79
80
81
82 public String getUrl() {
83 return this.url;
84 }
85
86
87
88
89
90
91
92 @Nonnull
93 public List<Notifier> getNotifiers() {
94 return this.notifiers;
95 }
96
97
98
99
100 public InputLocation getLocation(Object key) {
101 return locations != null ? locations.get(key) : null;
102 }
103
104
105
106
107 public Set<Object> getLocationKeys() {
108 return locations != null ? locations.keySet() : null;
109 }
110
111
112
113
114 public InputLocation getImportedFrom()
115 {
116 return importedFrom;
117 }
118
119
120
121
122
123
124 @Nonnull
125 public Builder with() {
126 return newBuilder(this);
127 }
128
129
130
131
132
133
134 @Nonnull
135 public CiManagement withSystem(String system) {
136 return newBuilder(this, true).system(system).build();
137 }
138
139
140
141
142
143
144 @Nonnull
145 public CiManagement withUrl(String url) {
146 return newBuilder(this, true).url(url).build();
147 }
148
149
150
151
152
153
154 @Nonnull
155 public CiManagement withNotifiers(Collection<Notifier> notifiers) {
156 return newBuilder(this, true).notifiers(notifiers).build();
157 }
158
159
160
161
162
163
164
165
166 @Nonnull
167 public static CiManagement newInstance() {
168 return newInstance(true);
169 }
170
171
172
173
174
175
176
177
178 @Nonnull
179 public static CiManagement newInstance(boolean withDefaults) {
180 return newBuilder(withDefaults).build();
181 }
182
183
184
185
186
187
188
189
190 @Nonnull
191 public static Builder newBuilder() {
192 return newBuilder(true);
193 }
194
195
196
197
198
199
200
201 @Nonnull
202 public static Builder newBuilder(boolean withDefaults) {
203 return new Builder(withDefaults);
204 }
205
206
207
208
209
210
211
212
213 @Nonnull
214 public static Builder newBuilder(CiManagement from) {
215 return newBuilder(from, false);
216 }
217
218
219
220
221
222
223
224
225 @Nonnull
226 public static Builder newBuilder(CiManagement from, boolean forceCopy) {
227 return new Builder(from, forceCopy);
228 }
229
230
231
232
233
234
235 @NotThreadSafe
236 public static class Builder
237 {
238 CiManagement base;
239 String system;
240 String url;
241 Collection<Notifier> notifiers;
242 Map<Object, InputLocation> locations;
243 InputLocation importedFrom;
244
245 protected Builder(boolean withDefaults) {
246 if (withDefaults) {
247 }
248 }
249
250 protected Builder(CiManagement base, boolean forceCopy) {
251 if (forceCopy) {
252 this.system = base.system;
253 this.url = base.url;
254 this.notifiers = base.notifiers;
255 this.locations = base.locations;
256 this.importedFrom = base.importedFrom;
257 } else {
258 this.base = base;
259 }
260 }
261
262 @Nonnull
263 public Builder system(String system) {
264 this.system = system;
265 return this;
266 }
267
268 @Nonnull
269 public Builder url(String url) {
270 this.url = url;
271 return this;
272 }
273
274 @Nonnull
275 public Builder notifiers(Collection<Notifier> notifiers) {
276 this.notifiers = notifiers;
277 return this;
278 }
279
280
281 @Nonnull
282 public Builder location(Object key, InputLocation location) {
283 if (location != null) {
284 if (!(this.locations instanceof HashMap)) {
285 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
286 }
287 this.locations.put(key, location);
288 }
289 return this;
290 }
291
292 @Nonnull
293 public Builder importedFrom(InputLocation importedFrom) {
294 this.importedFrom = importedFrom;
295 return this;
296 }
297
298 @Nonnull
299 public CiManagement build() {
300
301 if (base != null
302 && (system == null || system == base.system)
303 && (url == null || url == base.url)
304 && (notifiers == null || notifiers == base.notifiers)
305 ) {
306 return base;
307 }
308 return new CiManagement(this);
309 }
310 }
311
312 }