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