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