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