1
2
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
19
20 @Experimental
21 @Generated @ThreadSafe @Immutable
22 public class Organization
23 implements Serializable, InputLocationTracker
24 {
25
26
27
28 final String name;
29
30
31
32 final String url;
33
34 final InputLocation location;
35
36 final InputLocation nameLocation;
37
38 final InputLocation urlLocation;
39
40 final Map<Object, InputLocation> locations;
41
42
43
44
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
65
66
67
68 public String getName()
69 {
70 return this.name;
71 }
72
73
74
75
76
77
78 public String getUrl()
79 {
80 return this.url;
81 }
82
83
84
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
105
106
107
108 @Nonnull
109 public Builder with()
110 {
111 return newBuilder( this );
112 }
113
114
115
116
117
118
119 @Nonnull
120 public Organization withName( String name )
121 {
122 return with().name( name ).build();
123 }
124
125
126
127
128
129
130 @Nonnull
131 public Organization withUrl( String url )
132 {
133 return with().url( url ).build();
134 }
135
136
137
138
139
140
141
142
143 @Nonnull
144 public static Organization newInstance()
145 {
146 return newInstance( true );
147 }
148
149
150
151
152
153
154
155
156 @Nonnull
157 public static Organization newInstance( boolean withDefaults )
158 {
159 return newBuilder( withDefaults ).build();
160 }
161
162
163
164
165
166
167
168
169 @Nonnull
170 public static Builder newBuilder()
171 {
172 return newBuilder( true );
173 }
174
175
176
177
178
179
180
181 @Nonnull
182 public static Builder newBuilder( boolean withDefaults )
183 {
184 return new Builder( withDefaults );
185 }
186
187
188
189
190
191
192
193
194 @Nonnull
195 public static Builder newBuilder( Organization from )
196 {
197 return newBuilder( from, false );
198 }
199
200
201
202
203
204
205
206
207 @Nonnull
208 public static Builder newBuilder( Organization from, boolean forceCopy )
209 {
210 return new Builder( from, forceCopy );
211 }
212
213
214
215
216
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 }