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 java.util.Objects;
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
21
22
23 @Experimental
24 @Generated @ThreadSafe @Immutable
25 public class RepositoryBase
26 implements Serializable, InputLocationTracker
27 {
28
29
30
31
32
33 final String id;
34
35
36
37 final String name;
38
39
40
41 final String url;
42
43
44
45
46 final String layout;
47
48 final InputLocation location;
49
50 final InputLocation idLocation;
51
52 final InputLocation nameLocation;
53
54 final InputLocation urlLocation;
55
56 final InputLocation layoutLocation;
57
58 final Map<Object, InputLocation> locations;
59
60
61
62
63
64 RepositoryBase(
65 String id,
66 String name,
67 String url,
68 String layout,
69 Map<Object, InputLocation> locations,
70 InputLocation location,
71 InputLocation idLocation,
72 InputLocation nameLocation,
73 InputLocation urlLocation,
74 InputLocation layoutLocation
75 )
76 {
77 this.id = id;
78 this.name = name;
79 this.url = url;
80 this.layout = layout;
81 this.locations = ImmutableCollections.copy( locations );
82 this.location = location;
83 this.idLocation = idLocation;
84 this.nameLocation = nameLocation;
85 this.urlLocation = urlLocation;
86 this.layoutLocation = layoutLocation;
87 }
88
89 @Override
90 public boolean equals( Object o )
91 {
92 if ( this == o )
93 {
94 return true;
95 }
96 if ( o == null || !( o instanceof RepositoryBase ) )
97 {
98 return false;
99 }
100 RepositoryBase that = ( RepositoryBase ) o;
101 return Objects.equals( this.id, that.id );
102 }
103
104 @Override
105 public int hashCode()
106 {
107 return Objects.hash( id );
108 }
109
110
111
112
113
114
115
116
117 public String getId()
118 {
119 return this.id;
120 }
121
122
123
124
125
126
127 public String getName()
128 {
129 return this.name;
130 }
131
132
133
134
135
136
137 public String getUrl()
138 {
139 return this.url;
140 }
141
142
143
144
145
146
147
148 public String getLayout()
149 {
150 return this.layout;
151 }
152
153
154
155
156 public InputLocation getLocation( Object key )
157 {
158 if ( key instanceof String )
159 {
160 switch ( ( String ) key )
161 {
162 case "":
163 return location;
164 case "id":
165 return idLocation;
166 case "name":
167 return nameLocation;
168 case "url":
169 return urlLocation;
170 case "layout":
171 return layoutLocation;
172 }
173 }
174 return locations != null ? locations.get( key ) : null;
175 }
176
177
178
179
180
181
182 @Nonnull
183 public Builder with()
184 {
185 return newBuilder( this );
186 }
187
188
189
190
191
192
193 @Nonnull
194 public RepositoryBase withId( String id )
195 {
196 return with().id( id ).build();
197 }
198
199
200
201
202
203
204 @Nonnull
205 public RepositoryBase withName( String name )
206 {
207 return with().name( name ).build();
208 }
209
210
211
212
213
214
215 @Nonnull
216 public RepositoryBase withUrl( String url )
217 {
218 return with().url( url ).build();
219 }
220
221
222
223
224
225
226 @Nonnull
227 public RepositoryBase withLayout( String layout )
228 {
229 return with().layout( layout ).build();
230 }
231
232
233
234
235
236
237
238
239 @Nonnull
240 public static RepositoryBase newInstance()
241 {
242 return newInstance( true );
243 }
244
245
246
247
248
249
250
251
252 @Nonnull
253 public static RepositoryBase newInstance( boolean withDefaults )
254 {
255 return newBuilder( withDefaults ).build();
256 }
257
258
259
260
261
262
263
264
265 @Nonnull
266 public static Builder newBuilder()
267 {
268 return newBuilder( true );
269 }
270
271
272
273
274
275
276
277 @Nonnull
278 public static Builder newBuilder( boolean withDefaults )
279 {
280 return new Builder( withDefaults );
281 }
282
283
284
285
286
287
288
289
290 @Nonnull
291 public static Builder newBuilder( RepositoryBase from )
292 {
293 return newBuilder( from, false );
294 }
295
296
297
298
299
300
301
302
303 @Nonnull
304 public static Builder newBuilder( RepositoryBase from, boolean forceCopy )
305 {
306 return new Builder( from, forceCopy );
307 }
308
309
310
311
312
313
314 @NotThreadSafe
315 public static class Builder
316 {
317 RepositoryBase base;
318 String id;
319 String name;
320 String url;
321 String layout;
322 Map<Object, InputLocation> locations;
323
324 Builder( boolean withDefaults )
325 {
326 if ( withDefaults )
327 {
328 this.layout = "default";
329 }
330 }
331
332 Builder( RepositoryBase base, boolean forceCopy )
333 {
334 if ( forceCopy )
335 {
336 this.id = base.id;
337 this.name = base.name;
338 this.url = base.url;
339 this.layout = base.layout;
340 }
341 else
342 {
343 this.base = base;
344 }
345 }
346
347 @Nonnull
348 public Builder id( String id )
349 {
350 this.id = id;
351 return this;
352 }
353
354 @Nonnull
355 public Builder name( String name )
356 {
357 this.name = name;
358 return this;
359 }
360
361 @Nonnull
362 public Builder url( String url )
363 {
364 this.url = url;
365 return this;
366 }
367
368 @Nonnull
369 public Builder layout( String layout )
370 {
371 this.layout = layout;
372 return this;
373 }
374
375
376 @Nonnull
377 public Builder location( Object key, InputLocation location )
378 {
379 if ( location != null )
380 {
381 if ( this.locations == null )
382 {
383 this.locations = new HashMap<>();
384 }
385 this.locations.put( key, location );
386 }
387 return this;
388 }
389
390 @Nonnull
391 public RepositoryBase build()
392 {
393 if ( base != null
394 && ( id == null || id == base.id )
395 && ( name == null || name == base.name )
396 && ( url == null || url == base.url )
397 && ( layout == null || layout == base.layout )
398 )
399 {
400 return base;
401 }
402 Map<Object, InputLocation> locations = null;
403 InputLocation location = null;
404 InputLocation idLocation = null;
405 InputLocation nameLocation = null;
406 InputLocation urlLocation = null;
407 InputLocation layoutLocation = null;
408 if ( this.locations != null )
409 {
410 locations = this.locations;
411 location = locations.remove( "" );
412 idLocation = locations.remove( "id" );
413 nameLocation = locations.remove( "name" );
414 urlLocation = locations.remove( "url" );
415 layoutLocation = locations.remove( "layout" );
416 }
417 return new RepositoryBase(
418 id != null ? id : ( base != null ? base.id : null ),
419 name != null ? name : ( base != null ? base.name : null ),
420 url != null ? url : ( base != null ? base.url : null ),
421 layout != null ? layout : ( base != null ? base.layout : null ),
422 locations != null ? locations : ( base != null ? base.locations : null ),
423 location != null ? location : ( base != null ? base.location : null ),
424 idLocation != null ? idLocation : ( base != null ? base.idLocation : null ),
425 nameLocation != null ? nameLocation : ( base != null ? base.nameLocation : null ),
426 urlLocation != null ? urlLocation : ( base != null ? base.urlLocation : null ),
427 layoutLocation != null ? layoutLocation : ( base != null ? base.layoutLocation : null )
428 );
429 }
430 }
431
432 }