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