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