View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   //   Generated by Maven, any modifications will be overwritten.
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   * Definition of include or exclude patterns.
22   */
23  @Experimental
24  @Generated @ThreadSafe @Immutable
25  public class PatternSet
26      implements Serializable, InputLocationTracker
27  {
28      /**
29       * A list of patterns to include, e.g. {@code **/*.xml}.
30       */
31      final List<String> includes;
32      /**
33       * A list of patterns to exclude, e.g. {@code **&#47;*.xml}
34       */
35      final List<String> excludes;
36      /** Location of the xml element for this object. */
37      final InputLocation location;
38      /** Location of the xml element for the field includes. */
39      final InputLocation includesLocation;
40      /** Location of the xml element for the field excludes. */
41      final InputLocation excludesLocation;
42      /** Other locations */
43      final Map<Object, InputLocation> locations;
44  
45      /**
46        * Constructor for this class, package protected.
47        * @see Builder#build()
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       * A list of patterns to include, e.g. {@code **&#47;*.xml}.
68       *
69       * @return a {@code List<String>}
70       */
71      @Nonnull
72      public List<String> getIncludes()
73      {
74          return this.includes;
75      }
76  
77      /**
78       * A list of patterns to exclude, e.g. {@code **&#47;*.xml}
79       *
80       * @return a {@code List<String>}
81       */
82      @Nonnull
83      public List<String> getExcludes()
84      {
85          return this.excludes;
86      }
87  
88      /**
89       * Gets the location of the specified field in the input source.
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      * Creates a new builder with this object as the basis.
110      *
111      * @return a {@code Builder}
112      */
113     @Nonnull
114     public Builder with()
115     {
116         return newBuilder( this );
117     }
118     /**
119      * Creates a new {@code PatternSet} instance using the specified includes.
120      *
121      * @param includes the new {@code Collection<String>} to use
122      * @return a {@code PatternSet} with the specified includes
123      */
124     @Nonnull
125     public PatternSet withIncludes( Collection<String> includes )
126     {
127         return with().includes( includes ).build();
128     }
129     /**
130      * Creates a new {@code PatternSet} instance using the specified excludes.
131      *
132      * @param excludes the new {@code Collection<String>} to use
133      * @return a {@code PatternSet} with the specified excludes
134      */
135     @Nonnull
136     public PatternSet withExcludes( Collection<String> excludes )
137     {
138         return with().excludes( excludes ).build();
139     }
140 
141     /**
142      * Creates a new {@code PatternSet} instance.
143      * Equivalent to {@code newInstance( true )}.
144      * @see #newInstance(boolean)
145      *
146      * @return a new {@code PatternSet}
147      */
148     @Nonnull
149     public static PatternSet newInstance()
150     {
151         return newInstance( true );
152     }
153 
154     /**
155      * Creates a new {@code PatternSet} instance using default values or not.
156      * Equivalent to {@code newBuilder( withDefaults ).build()}.
157      *
158      * @param withDefaults the boolean indicating whether default values should be used
159      * @return a new {@code PatternSet}
160      */
161     @Nonnull
162     public static PatternSet newInstance( boolean withDefaults )
163     {
164         return newBuilder( withDefaults ).build();
165     }
166 
167     /**
168      * Creates a new {@code PatternSet} builder instance.
169      * Equivalent to {@code newBuilder( true )}.
170      * @see #newBuilder(boolean)
171      *
172      * @return a new {@code Builder}
173      */
174     @Nonnull
175     public static Builder newBuilder()
176     {
177         return newBuilder( true );
178     }
179 
180     /**
181      * Creates a new {@code PatternSet} builder instance using default values or not.
182      *
183      * @param withDefaults the boolean indicating whether default values should be used
184      * @return a new {@code Builder}
185      */
186     @Nonnull
187     public static Builder newBuilder( boolean withDefaults )
188     {
189         return new Builder( withDefaults );
190     }
191 
192     /**
193      * Creates a new {@code PatternSet} builder instance using the specified object as a basis.
194      * Equivalent to {@code newBuilder( from, false )}.
195      *
196      * @param from the {@code PatternSet} instance to use as a basis
197      * @return a new {@code Builder}
198      */
199     @Nonnull
200     public static Builder newBuilder( PatternSet from )
201     {
202         return newBuilder( from, false );
203     }
204 
205     /**
206      * Creates a new {@code PatternSet} builder instance using the specified object as a basis.
207      *
208      * @param from the {@code PatternSet} instance to use as a basis
209      * @param forceCopy the boolean indicating if a copy should be forced
210      * @return a new {@code Builder}
211      */
212     @Nonnull
213     public static Builder newBuilder( PatternSet from, boolean forceCopy )
214     {
215         return new Builder( from, forceCopy );
216     }
217 
218     /**
219      * Builder class used to create PatternSet instances.
220      * @see #with()
221      * @see #newBuilder()
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      * @see java.lang.Object#toString()
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 }