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