1
2
3
4
5 package org.apache.maven.api.toolchain;
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 TrackableBase
25 implements Serializable, InputLocationTracker
26 {
27
28 final Map<Object, InputLocation> locations;
29
30 final InputLocation importedFrom;
31
32
33
34
35
36 protected TrackableBase(Builder builder) {
37 Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
38 Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap();
39 Map<Object, InputLocation> mutableLocations = new HashMap<>();
40 this.importedFrom = builder.importedFrom;
41 mutableLocations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
42 this.locations = Collections.unmodifiableMap(mutableLocations);
43 }
44
45
46
47
48 public InputLocation getLocation(Object key) {
49 return locations != null ? locations.get(key) : null;
50 }
51
52
53
54
55 public Set<Object> getLocationKeys() {
56 return locations != null ? locations.keySet() : null;
57 }
58
59
60
61
62 public InputLocation getImportedFrom()
63 {
64 return importedFrom;
65 }
66
67
68
69
70
71
72 @Nonnull
73 public Builder with() {
74 return newBuilder(this);
75 }
76
77
78
79
80
81
82
83
84 @Nonnull
85 public static TrackableBase newInstance() {
86 return newInstance(true);
87 }
88
89
90
91
92
93
94
95
96 @Nonnull
97 public static TrackableBase newInstance(boolean withDefaults) {
98 return newBuilder(withDefaults).build();
99 }
100
101
102
103
104
105
106
107
108 @Nonnull
109 public static Builder newBuilder() {
110 return newBuilder(true);
111 }
112
113
114
115
116
117
118
119 @Nonnull
120 public static Builder newBuilder(boolean withDefaults) {
121 return new Builder(withDefaults);
122 }
123
124
125
126
127
128
129
130
131 @Nonnull
132 public static Builder newBuilder(TrackableBase from) {
133 return newBuilder(from, false);
134 }
135
136
137
138
139
140
141
142
143 @Nonnull
144 public static Builder newBuilder(TrackableBase from, boolean forceCopy) {
145 return new Builder(from, forceCopy);
146 }
147
148
149
150
151
152
153 @NotThreadSafe
154 public static class Builder
155 {
156 TrackableBase base;
157 Map<Object, InputLocation> locations;
158 InputLocation importedFrom;
159
160 protected Builder(boolean withDefaults) {
161 if (withDefaults) {
162 }
163 }
164
165 protected Builder(TrackableBase base, boolean forceCopy) {
166 if (forceCopy) {
167 this.locations = base.locations;
168 this.importedFrom = base.importedFrom;
169 } else {
170 this.base = base;
171 }
172 }
173
174
175 @Nonnull
176 public Builder location(Object key, InputLocation location) {
177 if (location != null) {
178 if (!(this.locations instanceof HashMap)) {
179 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
180 }
181 this.locations.put(key, location);
182 }
183 return this;
184 }
185
186 @Nonnull
187 public Builder importedFrom(InputLocation importedFrom) {
188 this.importedFrom = importedFrom;
189 return this;
190 }
191
192 @Nonnull
193 public TrackableBase build() {
194
195 if (base != null
196 ) {
197 return base;
198 }
199 return new TrackableBase(this);
200 }
201 }
202
203 }