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