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