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