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 public InputLocation getLocation(Object key) {
78 return locations.get(key);
79 }
80
81
82
83
84 public Set<Object> getLocationKeys() {
85 return locations.keySet();
86 }
87
88 protected Stream<Object> getLocationKeyStream() {
89 return locations.keySet().stream();
90 }
91
92
93
94
95 public InputLocation getImportedFrom()
96 {
97 return importedFrom;
98 }
99
100
101
102
103
104
105 @Nonnull
106 public Builder with() {
107 return newBuilder(this);
108 }
109
110
111
112
113
114
115 @Nonnull
116 public IssueManagement withSystem(String system) {
117 return newBuilder(this, true).system(system).build();
118 }
119
120
121
122
123
124
125 @Nonnull
126 public IssueManagement withUrl(String url) {
127 return newBuilder(this, true).url(url).build();
128 }
129
130
131
132
133
134
135
136
137 @Nonnull
138 public static IssueManagement newInstance() {
139 return newInstance(true);
140 }
141
142
143
144
145
146
147
148
149 @Nonnull
150 public static IssueManagement newInstance(boolean withDefaults) {
151 return newBuilder(withDefaults).build();
152 }
153
154
155
156
157
158
159
160
161 @Nonnull
162 public static Builder newBuilder() {
163 return newBuilder(true);
164 }
165
166
167
168
169
170
171
172 @Nonnull
173 public static Builder newBuilder(boolean withDefaults) {
174 return new Builder(withDefaults);
175 }
176
177
178
179
180
181
182
183
184 @Nonnull
185 public static Builder newBuilder(IssueManagement from) {
186 return newBuilder(from, false);
187 }
188
189
190
191
192
193
194
195
196 @Nonnull
197 public static Builder newBuilder(IssueManagement from, boolean forceCopy) {
198 return new Builder(from, forceCopy);
199 }
200
201
202
203
204
205
206 @NotThreadSafe
207 public static class Builder
208 {
209 IssueManagement base;
210 String system;
211 String url;
212 Map<Object, InputLocation> locations;
213 InputLocation importedFrom;
214
215 protected Builder(boolean withDefaults) {
216 if (withDefaults) {
217 }
218 }
219
220 protected Builder(IssueManagement base, boolean forceCopy) {
221 if (forceCopy) {
222 this.system = base.system;
223 this.url = base.url;
224 this.locations = base.locations;
225 this.importedFrom = base.importedFrom;
226 } else {
227 this.base = base;
228 }
229 }
230
231 @Nonnull
232 public Builder system(String system) {
233 this.system = system;
234 return this;
235 }
236
237 @Nonnull
238 public Builder url(String url) {
239 this.url = url;
240 return this;
241 }
242
243
244 @Nonnull
245 public Builder location(Object key, InputLocation location) {
246 if (location != null) {
247 if (!(this.locations instanceof HashMap)) {
248 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
249 }
250 this.locations.put(key, location);
251 }
252 return this;
253 }
254
255 @Nonnull
256 public Builder importedFrom(InputLocation importedFrom) {
257 this.importedFrom = importedFrom;
258 return this;
259 }
260
261 @Nonnull
262 public IssueManagement build() {
263
264 if (base != null
265 && (system == null || system == base.system)
266 && (url == null || url == base.url)
267 ) {
268 return base;
269 }
270 return new IssueManagement(this);
271 }
272
273 Map<Object, InputLocation> computeLocations() {
274 Map<Object, InputLocation> newlocs = locations != null ? locations : Map.of();
275 Map<Object, InputLocation> oldlocs = base != null ? base.locations : Map.of();
276 if (newlocs.isEmpty()) {
277 return Map.copyOf(oldlocs);
278 }
279 if (oldlocs.isEmpty()) {
280 return Map.copyOf(newlocs);
281 }
282 return Stream.concat(newlocs.entrySet().stream(), oldlocs.entrySet().stream())
283
284 .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v1));
285 }
286 }
287
288
289
290
291
292
293 public String toString()
294 {
295 return "IssueManagement {system=" + getSystem() + ", url=" + getUrl() + "}";
296 }
297
298
299 }