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