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