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