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