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