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