1   
2   
3   
4   
5   package org.apache.maven.api.model;
6   
7   import java.io.Serializable;
8   import java.util.Collections;
9   import java.util.HashMap;
10  import java.util.Map;
11  import org.apache.maven.api.annotations.Experimental;
12  import org.apache.maven.api.annotations.Generated;
13  import org.apache.maven.api.annotations.Immutable;
14  import org.apache.maven.api.annotations.Nonnull;
15  import org.apache.maven.api.annotations.NotThreadSafe;
16  import org.apache.maven.api.annotations.ThreadSafe;
17  
18  
19  
20  
21  @Experimental
22  @Generated @ThreadSafe @Immutable
23  public class Site
24      implements Serializable, InputLocationTracker
25  {
26      
27  
28  
29  
30      final String id;
31      
32  
33  
34      final String name;
35      
36  
37  
38  
39  
40      final String url;
41      
42  
43  
44  
45  
46  
47  
48      final String childSiteUrlInheritAppendPath;
49      
50      final InputLocation location;
51      
52      final InputLocation idLocation;
53      
54      final InputLocation nameLocation;
55      
56      final InputLocation urlLocation;
57      
58      final InputLocation childSiteUrlInheritAppendPathLocation;
59      
60      final Map<Object, InputLocation> locations;
61  
62      
63  
64  
65  
66      Site(
67          String id,
68          String name,
69          String url,
70          String childSiteUrlInheritAppendPath,
71          Map<Object, InputLocation> locations,
72          InputLocation location,
73          InputLocation idLocation,
74          InputLocation nameLocation,
75          InputLocation urlLocation,
76          InputLocation childSiteUrlInheritAppendPathLocation
77      )
78      {
79          this.id = id;
80          this.name = name;
81          this.url = url;
82          this.childSiteUrlInheritAppendPath = childSiteUrlInheritAppendPath;
83          this.locations = ImmutableCollections.copy( locations );
84          this.location = location;
85          this.idLocation = idLocation;
86          this.nameLocation = nameLocation;
87          this.urlLocation = urlLocation;
88          this.childSiteUrlInheritAppendPathLocation = childSiteUrlInheritAppendPathLocation;
89      }
90  
91      
92  
93  
94  
95  
96  
97      public String getId()
98      {
99          return this.id;
100     }
101 
102     
103 
104 
105 
106 
107     public String getName()
108     {
109         return this.name;
110     }
111 
112     
113 
114 
115 
116 
117 
118 
119     public String getUrl()
120     {
121         return this.url;
122     }
123 
124     
125 
126 
127 
128 
129 
130 
131 
132 
133     public String getChildSiteUrlInheritAppendPath()
134     {
135         return this.childSiteUrlInheritAppendPath;
136     }
137 
138     
139 
140 
141     public InputLocation getLocation( Object key )
142     {
143         if ( key instanceof String )
144         {
145             switch ( ( String ) key )
146             {
147                 case "":
148                     return location;
149                 case "id":
150                     return idLocation;
151                 case "name":
152                     return nameLocation;
153                 case "url":
154                     return urlLocation;
155                 case "childSiteUrlInheritAppendPath":
156                     return childSiteUrlInheritAppendPathLocation;
157             }
158         }
159         return locations != null ? locations.get( key ) : null;
160     }
161 
162     
163 
164 
165 
166 
167     @Nonnull
168     public Builder with()
169     {
170         return newBuilder( this );
171     }
172     
173 
174 
175 
176 
177 
178     @Nonnull
179     public Site withId( String id )
180     {
181         return with().id( id ).build();
182     }
183     
184 
185 
186 
187 
188 
189     @Nonnull
190     public Site withName( String name )
191     {
192         return with().name( name ).build();
193     }
194     
195 
196 
197 
198 
199 
200     @Nonnull
201     public Site withUrl( String url )
202     {
203         return with().url( url ).build();
204     }
205     
206 
207 
208 
209 
210 
211     @Nonnull
212     public Site withChildSiteUrlInheritAppendPath( String childSiteUrlInheritAppendPath )
213     {
214         return with().childSiteUrlInheritAppendPath( childSiteUrlInheritAppendPath ).build();
215     }
216 
217     
218 
219 
220 
221 
222 
223 
224     @Nonnull
225     public static Site newInstance()
226     {
227         return newInstance( true );
228     }
229 
230     
231 
232 
233 
234 
235 
236 
237     @Nonnull
238     public static Site newInstance( boolean withDefaults )
239     {
240         return newBuilder( withDefaults ).build();
241     }
242 
243     
244 
245 
246 
247 
248 
249 
250     @Nonnull
251     public static Builder newBuilder()
252     {
253         return newBuilder( true );
254     }
255 
256     
257 
258 
259 
260 
261 
262     @Nonnull
263     public static Builder newBuilder( boolean withDefaults )
264     {
265         return new Builder( withDefaults );
266     }
267 
268     
269 
270 
271 
272 
273 
274 
275     @Nonnull
276     public static Builder newBuilder( Site from )
277     {
278         return newBuilder( from, false );
279     }
280 
281     
282 
283 
284 
285 
286 
287 
288     @Nonnull
289     public static Builder newBuilder( Site from, boolean forceCopy )
290     {
291         return new Builder( from, forceCopy );
292     }
293 
294     
295 
296 
297 
298 
299     @NotThreadSafe
300     public static class Builder
301     {
302         Site base;
303         String id;
304         String name;
305         String url;
306         String childSiteUrlInheritAppendPath;
307         Map<Object, InputLocation> locations;
308 
309         Builder( boolean withDefaults )
310         {
311             if ( withDefaults )
312             {
313             }
314         }
315 
316         Builder( Site base, boolean forceCopy )
317         {
318             if ( forceCopy )
319             {
320                 this.id = base.id;
321                 this.name = base.name;
322                 this.url = base.url;
323                 this.childSiteUrlInheritAppendPath = base.childSiteUrlInheritAppendPath;
324             }
325             else
326             {
327                 this.base = base;
328             }
329         }
330 
331         @Nonnull
332         public Builder id( String id )
333         {
334             this.id = id;
335             return this;
336         }
337 
338         @Nonnull
339         public Builder name( String name )
340         {
341             this.name = name;
342             return this;
343         }
344 
345         @Nonnull
346         public Builder url( String url )
347         {
348             this.url = url;
349             return this;
350         }
351 
352         @Nonnull
353         public Builder childSiteUrlInheritAppendPath( String childSiteUrlInheritAppendPath )
354         {
355             this.childSiteUrlInheritAppendPath = childSiteUrlInheritAppendPath;
356             return this;
357         }
358 
359 
360         @Nonnull
361         public Builder location( Object key, InputLocation location )
362         {
363             if ( location != null )
364             {
365                 if ( this.locations == null )
366                 {
367                     this.locations = new HashMap<>();
368                 }
369                 this.locations.put( key, location );
370             }
371             return this;
372         }
373 
374         @Nonnull
375         public Site build()
376         {
377             if ( base != null
378                     && ( id == null || id == base.id )
379                     && ( name == null || name == base.name )
380                     && ( url == null || url == base.url )
381                     && ( childSiteUrlInheritAppendPath == null || childSiteUrlInheritAppendPath == base.childSiteUrlInheritAppendPath )
382             )
383             {
384                 return base;
385             }
386             Map<Object, InputLocation> locations = null;
387             InputLocation location = null;
388             InputLocation idLocation = null;
389             InputLocation nameLocation = null;
390             InputLocation urlLocation = null;
391             InputLocation childSiteUrlInheritAppendPathLocation = null;
392             if ( this.locations != null )
393             {
394                 locations = this.locations;
395                 location = locations.remove( "" );
396                 idLocation = locations.remove( "id" );
397                 nameLocation = locations.remove( "name" );
398                 urlLocation = locations.remove( "url" );
399                 childSiteUrlInheritAppendPathLocation = locations.remove( "childSiteUrlInheritAppendPath" );
400             }
401             return new Site(
402                 id != null ? id : ( base != null ? base.id : null ),
403                 name != null ? name : ( base != null ? base.name : null ),
404                 url != null ? url : ( base != null ? base.url : null ),
405                 childSiteUrlInheritAppendPath != null ? childSiteUrlInheritAppendPath : ( base != null ? base.childSiteUrlInheritAppendPath : null ),
406                 locations != null ? locations : ( base != null ? base.locations : null ),
407                 location != null ? location : ( base != null ? base.location : null ),
408                 idLocation != null ? idLocation : ( base != null ? base.idLocation : null ),
409                 nameLocation != null ? nameLocation : ( base != null ? base.nameLocation : null ),
410                 urlLocation != null ? urlLocation : ( base != null ? base.urlLocation : null ),
411                 childSiteUrlInheritAppendPathLocation != null ? childSiteUrlInheritAppendPathLocation : ( base != null ? base.childSiteUrlInheritAppendPathLocation : null )
412             );
413         }
414     }
415 
416 
417             
418 
419     public boolean isChildSiteUrlInheritAppendPath()
420     {
421         return ( getChildSiteUrlInheritAppendPath() != null ) ? Boolean.parseBoolean( getChildSiteUrlInheritAppendPath() ) : true;
422     }
423 
424             
425           
426 }