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