View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   //   Generated by Maven, any modifications will be overwritten.
3   // ==============================================================
4   package org.apache.maven.api.model;
5   
6   import java.io.Serializable;
7   import java.util.Collections;
8   import java.util.HashMap;
9   import java.util.Map;
10  import org.apache.maven.api.annotations.Experimental;
11  import org.apache.maven.api.annotations.Generated;
12  import org.apache.maven.api.annotations.Immutable;
13  import org.apache.maven.api.annotations.Nonnull;
14  import org.apache.maven.api.annotations.NotThreadSafe;
15  import org.apache.maven.api.annotations.ThreadSafe;
16  
17  /**
18   * Specifies the organization that produces this project.
19   */
20  @Experimental
21  @Generated @ThreadSafe @Immutable
22  public class Organization
23      implements Serializable, InputLocationTracker
24  {
25      /**
26       * The full name of the organization.
27       */
28      final String name;
29      /**
30       * The URL to the organization's home page.
31       */
32      final String url;
33      /** Location of the xml element for this object. */
34      final InputLocation location;
35      /** Location of the xml element for the field name. */
36      final InputLocation nameLocation;
37      /** Location of the xml element for the field url. */
38      final InputLocation urlLocation;
39      /** Other locations */
40      final Map<Object, InputLocation> locations;
41  
42      /**
43        * Constructor for this class, package protected.
44        * @see Builder#build()
45        */
46      Organization(
47          String name,
48          String url,
49          Map<Object, InputLocation> locations,
50          InputLocation location,
51          InputLocation nameLocation,
52          InputLocation urlLocation
53      )
54      {
55          this.name = name;
56          this.url = url;
57          this.locations = ImmutableCollections.copy( locations );
58          this.location = location;
59          this.nameLocation = nameLocation;
60          this.urlLocation = urlLocation;
61      }
62  
63      /**
64       * The full name of the organization.
65       *
66       * @return a {@code String}
67       */
68      public String getName()
69      {
70          return this.name;
71      }
72  
73      /**
74       * The URL to the organization's home page.
75       *
76       * @return a {@code String}
77       */
78      public String getUrl()
79      {
80          return this.url;
81      }
82  
83      /**
84       * Gets the location of the specified field in the input source.
85       */
86      public InputLocation getLocation( Object key )
87      {
88          if ( key instanceof String )
89          {
90              switch ( ( String ) key )
91              {
92                  case "":
93                      return location;
94                  case "name":
95                      return nameLocation;
96                  case "url":
97                      return urlLocation;
98              }
99          }
100         return locations != null ? locations.get( key ) : null;
101     }
102 
103     /**
104      * Creates a new builder with this object as the basis.
105      *
106      * @return a {@code Builder}
107      */
108     @Nonnull
109     public Builder with()
110     {
111         return newBuilder( this );
112     }
113     /**
114      * Creates a new {@code Organization} instance using the specified name.
115      *
116      * @param name the new {@code String} to use
117      * @return a {@code Organization} with the specified name
118      */
119     @Nonnull
120     public Organization withName( String name )
121     {
122         return with().name( name ).build();
123     }
124     /**
125      * Creates a new {@code Organization} instance using the specified url.
126      *
127      * @param url the new {@code String} to use
128      * @return a {@code Organization} with the specified url
129      */
130     @Nonnull
131     public Organization withUrl( String url )
132     {
133         return with().url( url ).build();
134     }
135 
136     /**
137      * Creates a new {@code Organization} instance.
138      * Equivalent to {@code newInstance( true )}.
139      * @see #newInstance(boolean)
140      *
141      * @return a new {@code Organization}
142      */
143     @Nonnull
144     public static Organization newInstance()
145     {
146         return newInstance( true );
147     }
148 
149     /**
150      * Creates a new {@code Organization} instance using default values or not.
151      * Equivalent to {@code newBuilder( withDefaults ).build()}.
152      *
153      * @param withDefaults the boolean indicating whether default values should be used
154      * @return a new {@code Organization}
155      */
156     @Nonnull
157     public static Organization newInstance( boolean withDefaults )
158     {
159         return newBuilder( withDefaults ).build();
160     }
161 
162     /**
163      * Creates a new {@code Organization} builder instance.
164      * Equivalent to {@code newBuilder( true )}.
165      * @see #newBuilder(boolean)
166      *
167      * @return a new {@code Builder}
168      */
169     @Nonnull
170     public static Builder newBuilder()
171     {
172         return newBuilder( true );
173     }
174 
175     /**
176      * Creates a new {@code Organization} builder instance using default values or not.
177      *
178      * @param withDefaults the boolean indicating whether default values should be used
179      * @return a new {@code Builder}
180      */
181     @Nonnull
182     public static Builder newBuilder( boolean withDefaults )
183     {
184         return new Builder( withDefaults );
185     }
186 
187     /**
188      * Creates a new {@code Organization} builder instance using the specified object as a basis.
189      * Equivalent to {@code newBuilder( from, false )}.
190      *
191      * @param from the {@code Organization} instance to use as a basis
192      * @return a new {@code Builder}
193      */
194     @Nonnull
195     public static Builder newBuilder( Organization from )
196     {
197         return newBuilder( from, false );
198     }
199 
200     /**
201      * Creates a new {@code Organization} builder instance using the specified object as a basis.
202      *
203      * @param from the {@code Organization} instance to use as a basis
204      * @param forceCopy the boolean indicating if a copy should be forced
205      * @return a new {@code Builder}
206      */
207     @Nonnull
208     public static Builder newBuilder( Organization from, boolean forceCopy )
209     {
210         return new Builder( from, forceCopy );
211     }
212 
213     /**
214      * Builder class used to create Organization instances.
215      * @see #with()
216      * @see #newBuilder()
217      */
218     @NotThreadSafe
219     public static class Builder
220     {
221         Organization base;
222         String name;
223         String url;
224         Map<Object, InputLocation> locations;
225 
226         Builder( boolean withDefaults )
227         {
228             if ( withDefaults )
229             {
230             }
231         }
232 
233         Builder( Organization base, boolean forceCopy )
234         {
235             if ( forceCopy )
236             {
237                 this.name = base.name;
238                 this.url = base.url;
239             }
240             else
241             {
242                 this.base = base;
243             }
244         }
245 
246         @Nonnull
247         public Builder name( String name )
248         {
249             this.name = name;
250             return this;
251         }
252 
253         @Nonnull
254         public Builder url( String url )
255         {
256             this.url = url;
257             return this;
258         }
259 
260 
261         @Nonnull
262         public Builder location( Object key, InputLocation location )
263         {
264             if ( location != null )
265             {
266                 if ( this.locations == null )
267                 {
268                     this.locations = new HashMap<>();
269                 }
270                 this.locations.put( key, location );
271             }
272             return this;
273         }
274 
275         @Nonnull
276         public Organization build()
277         {
278             if ( base != null
279                     && ( name == null || name == base.name )
280                     && ( url == null || url == base.url )
281             )
282             {
283                 return base;
284             }
285             Map<Object, InputLocation> locations = null;
286             InputLocation location = null;
287             InputLocation nameLocation = null;
288             InputLocation urlLocation = null;
289             if ( this.locations != null )
290             {
291                 locations = this.locations;
292                 location = locations.remove( "" );
293                 nameLocation = locations.remove( "name" );
294                 urlLocation = locations.remove( "url" );
295             }
296             return new Organization(
297                 name != null ? name : ( base != null ? base.name : null ),
298                 url != null ? url : ( base != null ? base.url : null ),
299                 locations != null ? locations : ( base != null ? base.locations : null ),
300                 location != null ? location : ( base != null ? base.location : null ),
301                 nameLocation != null ? nameLocation : ( base != null ? base.nameLocation : null ),
302                 urlLocation != null ? urlLocation : ( base != null ? base.urlLocation : null )
303             );
304         }
305     }
306 
307 }