1
2
3
4 package org.apache.maven.api.model;
5
6 import java.io.Serializable;
7 import java.util.ArrayList;
8 import java.util.Collection;
9 import java.util.Collections;
10 import java.util.HashMap;
11 import java.util.List;
12 import java.util.Map;
13 import org.apache.maven.api.annotations.Experimental;
14 import org.apache.maven.api.annotations.Generated;
15 import org.apache.maven.api.annotations.Immutable;
16 import org.apache.maven.api.annotations.Nonnull;
17 import org.apache.maven.api.annotations.NotThreadSafe;
18 import org.apache.maven.api.annotations.ThreadSafe;
19
20
21
22
23 @Experimental
24 @Generated @ThreadSafe @Immutable
25 public class PatternSet
26 implements Serializable, InputLocationTracker
27 {
28
29
30
31 final List<String> includes;
32
33
34
35 final List<String> excludes;
36
37 final InputLocation location;
38
39 final InputLocation includesLocation;
40
41 final InputLocation excludesLocation;
42
43 final Map<Object, InputLocation> locations;
44
45
46
47
48
49 PatternSet(
50 Collection<String> includes,
51 Collection<String> excludes,
52 Map<Object, InputLocation> locations,
53 InputLocation location,
54 InputLocation includesLocation,
55 InputLocation excludesLocation
56 )
57 {
58 this.includes = ImmutableCollections.copy( includes );
59 this.excludes = ImmutableCollections.copy( excludes );
60 this.locations = ImmutableCollections.copy( locations );
61 this.location = location;
62 this.includesLocation = includesLocation;
63 this.excludesLocation = excludesLocation;
64 }
65
66
67
68
69
70
71 @Nonnull
72 public List<String> getIncludes()
73 {
74 return this.includes;
75 }
76
77
78
79
80
81
82 @Nonnull
83 public List<String> getExcludes()
84 {
85 return this.excludes;
86 }
87
88
89
90
91 public InputLocation getLocation( Object key )
92 {
93 if ( key instanceof String )
94 {
95 switch ( ( String ) key )
96 {
97 case "":
98 return location;
99 case "includes":
100 return includesLocation;
101 case "excludes":
102 return excludesLocation;
103 }
104 }
105 return locations != null ? locations.get( key ) : null;
106 }
107
108
109
110
111
112
113 @Nonnull
114 public Builder with()
115 {
116 return newBuilder( this );
117 }
118
119
120
121
122
123
124 @Nonnull
125 public PatternSet withIncludes( Collection<String> includes )
126 {
127 return with().includes( includes ).build();
128 }
129
130
131
132
133
134
135 @Nonnull
136 public PatternSet withExcludes( Collection<String> excludes )
137 {
138 return with().excludes( excludes ).build();
139 }
140
141
142
143
144
145
146
147
148 @Nonnull
149 public static PatternSet newInstance()
150 {
151 return newInstance( true );
152 }
153
154
155
156
157
158
159
160
161 @Nonnull
162 public static PatternSet newInstance( boolean withDefaults )
163 {
164 return newBuilder( withDefaults ).build();
165 }
166
167
168
169
170
171
172
173
174 @Nonnull
175 public static Builder newBuilder()
176 {
177 return newBuilder( true );
178 }
179
180
181
182
183
184
185
186 @Nonnull
187 public static Builder newBuilder( boolean withDefaults )
188 {
189 return new Builder( withDefaults );
190 }
191
192
193
194
195
196
197
198
199 @Nonnull
200 public static Builder newBuilder( PatternSet from )
201 {
202 return newBuilder( from, false );
203 }
204
205
206
207
208
209
210
211
212 @Nonnull
213 public static Builder newBuilder( PatternSet from, boolean forceCopy )
214 {
215 return new Builder( from, forceCopy );
216 }
217
218
219
220
221
222
223 @NotThreadSafe
224 public static class Builder
225 {
226 PatternSet base;
227 Collection<String> includes;
228 Collection<String> excludes;
229 Map<Object, InputLocation> locations;
230
231 Builder( boolean withDefaults )
232 {
233 if ( withDefaults )
234 {
235 }
236 }
237
238 Builder( PatternSet base, boolean forceCopy )
239 {
240 if ( forceCopy )
241 {
242 this.includes = base.includes;
243 this.excludes = base.excludes;
244 }
245 else
246 {
247 this.base = base;
248 }
249 }
250
251 @Nonnull
252 public Builder includes( Collection<String> includes )
253 {
254 this.includes = includes;
255 return this;
256 }
257
258 @Nonnull
259 public Builder excludes( Collection<String> excludes )
260 {
261 this.excludes = excludes;
262 return this;
263 }
264
265
266 @Nonnull
267 public Builder location( Object key, InputLocation location )
268 {
269 if ( location != null )
270 {
271 if ( this.locations == null )
272 {
273 this.locations = new HashMap<>();
274 }
275 this.locations.put( key, location );
276 }
277 return this;
278 }
279
280 @Nonnull
281 public PatternSet build()
282 {
283 if ( base != null
284 && ( includes == null || includes == base.includes )
285 && ( excludes == null || excludes == base.excludes )
286 )
287 {
288 return base;
289 }
290 Map<Object, InputLocation> locations = null;
291 InputLocation location = null;
292 InputLocation includesLocation = null;
293 InputLocation excludesLocation = null;
294 if ( this.locations != null )
295 {
296 locations = this.locations;
297 location = locations.remove( "" );
298 includesLocation = locations.remove( "includes" );
299 excludesLocation = locations.remove( "excludes" );
300 }
301 return new PatternSet(
302 includes != null ? includes : ( base != null ? base.includes : null ),
303 excludes != null ? excludes : ( base != null ? base.excludes : null ),
304 locations != null ? locations : ( base != null ? base.locations : null ),
305 location != null ? location : ( base != null ? base.location : null ),
306 includesLocation != null ? includesLocation : ( base != null ? base.includesLocation : null ),
307 excludesLocation != null ? excludesLocation : ( base != null ? base.excludesLocation : null )
308 );
309 }
310 }
311
312
313
314
315
316
317 public String toString()
318 {
319 StringBuilder sb = new StringBuilder( 128 );
320
321 sb.append("PatternSet [includes: {");
322 for (java.util.Iterator i = getIncludes().iterator(); i.hasNext(); )
323 {
324 String str = (String) i.next();
325 sb.append(str).append(", ");
326 }
327 if (sb.substring(sb.length() - 2).equals(", ")) sb.delete(sb.length() - 2, sb.length());
328
329 sb.append("}, excludes: {");
330 for (java.util.Iterator i = getExcludes().iterator(); i.hasNext(); )
331 {
332 String str = (String) i.next();
333 sb.append(str).append(", ");
334 }
335 if (sb.substring(sb.length() - 2).equals(", ")) sb.delete(sb.length() - 2, sb.length());
336
337 sb.append("}]");
338 return sb.toString();
339 }
340
341
342 }