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