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