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.Objects;
12 import java.util.Optional;
13 import java.util.Set;
14 import java.util.stream.Collectors;
15 import java.util.stream.Stream;
16 import org.apache.maven.api.annotations.Experimental;
17 import org.apache.maven.api.annotations.Generated;
18 import org.apache.maven.api.annotations.Immutable;
19 import org.apache.maven.api.annotations.Nonnull;
20 import org.apache.maven.api.annotations.NotThreadSafe;
21 import org.apache.maven.api.annotations.ThreadSafe;
22
23
24
25
26
27 @Experimental
28 @Generated @ThreadSafe @Immutable
29 public class IssueManagement
30 implements Serializable, InputLocationTracker
31 {
32
33
34
35 final String system;
36
37
38
39 final String url;
40
41 final Map<Object, InputLocation> locations;
42
43 final InputLocation importedFrom;
44
45
46
47
48
49 protected IssueManagement(Builder builder) {
50 this.system = builder.system != null ? builder.system : (builder.base != null ? builder.base.system : null);
51 this.url = builder.url != null ? builder.url : (builder.base != null ? builder.base.url : null);
52 this.locations = builder.computeLocations();
53 this.importedFrom = builder.importedFrom;
54 }
55
56
57
58
59
60
61 public String getSystem() {
62 return this.system;
63 }
64
65
66
67
68
69
70 public String getUrl() {
71 return this.url;
72 }
73
74
75
76
77
78
79
80
81 public InputLocation getLocation(Object key) {
82 Objects.requireNonNull(key, "key");
83 return locations.get(key);
84 }
85
86
87
88
89 public Set<Object> getLocationKeys() {
90 return locations.keySet();
91 }
92
93 protected Stream<Object> getLocationKeyStream() {
94 return locations.keySet().stream();
95 }
96
97
98
99
100 public InputLocation getImportedFrom() {
101 return importedFrom;
102 }
103
104
105
106
107
108
109 @Nonnull
110 public Builder with() {
111 return newBuilder(this);
112 }
113
114
115
116
117
118
119 @Nonnull
120 public IssueManagement withSystem(String system) {
121 return newBuilder(this, true).system(system).build();
122 }
123
124
125
126
127
128
129 @Nonnull
130 public IssueManagement withUrl(String url) {
131 return newBuilder(this, true).url(url).build();
132 }
133
134
135
136
137
138
139
140
141 @Nonnull
142 public static IssueManagement newInstance() {
143 return newInstance(true);
144 }
145
146
147
148
149
150
151
152
153 @Nonnull
154 public static IssueManagement newInstance(boolean withDefaults) {
155 return newBuilder(withDefaults).build();
156 }
157
158
159
160
161
162
163
164
165 @Nonnull
166 public static Builder newBuilder() {
167 return newBuilder(true);
168 }
169
170
171
172
173
174
175
176 @Nonnull
177 public static Builder newBuilder(boolean withDefaults) {
178 return new Builder(withDefaults);
179 }
180
181
182
183
184
185
186
187
188 @Nonnull
189 public static Builder newBuilder(IssueManagement from) {
190 return newBuilder(from, false);
191 }
192
193
194
195
196
197
198
199
200 @Nonnull
201 public static Builder newBuilder(IssueManagement from, boolean forceCopy) {
202 return new Builder(from, forceCopy);
203 }
204
205
206
207
208
209
210 @NotThreadSafe
211 public static class Builder
212 {
213 IssueManagement base;
214 String system;
215 String url;
216 Map<Object, InputLocation> locations;
217 InputLocation importedFrom;
218
219 protected Builder(boolean withDefaults) {
220 if (withDefaults) {
221 }
222 }
223
224 protected Builder(IssueManagement base, boolean forceCopy) {
225 if (forceCopy) {
226 this.system = base.system;
227 this.url = base.url;
228 this.locations = base.locations;
229 this.importedFrom = base.importedFrom;
230 } else {
231 this.base = base;
232 }
233 }
234
235 @Nonnull
236 public Builder system(String system) {
237 this.system = system;
238 return this;
239 }
240
241 @Nonnull
242 public Builder url(String url) {
243 this.url = url;
244 return this;
245 }
246
247
248 @Nonnull
249 public Builder location(Object key, InputLocation location) {
250 if (location != null) {
251 if (!(this.locations instanceof HashMap)) {
252 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
253 }
254 this.locations.put(key, location);
255 }
256 return this;
257 }
258
259 @Nonnull
260 public Builder importedFrom(InputLocation importedFrom) {
261 this.importedFrom = importedFrom;
262 return this;
263 }
264
265 @Nonnull
266 public IssueManagement build() {
267
268 if (base != null
269 && (system == null || system == base.system)
270 && (url == null || url == base.url)
271 ) {
272 return base;
273 }
274 return new IssueManagement(this);
275 }
276
277 Map<Object, InputLocation> computeLocations() {
278 Map<Object, InputLocation> newlocs = locations != null ? locations : Map.of();
279 Map<Object, InputLocation> oldlocs = base != null ? base.locations : Map.of();
280 if (newlocs.isEmpty()) {
281 return Map.copyOf(oldlocs);
282 }
283 if (oldlocs.isEmpty()) {
284 return Map.copyOf(newlocs);
285 }
286 return Stream.concat(newlocs.entrySet().stream(), oldlocs.entrySet().stream())
287
288 .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v1));
289 }
290 }
291
292
293
294
295
296
297 public String toString()
298 {
299 return "IssueManagement {system=" + getSystem() + ", url=" + getUrl() + "}";
300 }
301
302
303 }