View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   //  Generated by Modello Velocity from model.vm
3   //  template, any modifications will be overwritten.
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   * The {@code <exclusion>} element contains informations required to exclude
20   * an artifact to the project.
21   */
22  @Experimental
23  @Generated @ThreadSafe @Immutable
24  public class Exclusion
25      implements Serializable, InputLocationTracker
26  {
27      /**
28       * The group ID of the project to exclude.
29       */
30      final String groupId;
31      /**
32       * The artifact ID of the project to exclude.
33       */
34      final String artifactId;
35      /** Locations */
36      final Map<Object, InputLocation> locations;
37  
38      /**
39        * Constructor for this class, package protected.
40        * @see Builder#build()
41        */
42      Exclusion(
43          String groupId,
44          String artifactId,
45          Map<Object, InputLocation> locations
46      ) {
47          this.groupId = groupId;
48          this.artifactId = artifactId;
49          this.locations = ImmutableCollections.copy(locations);
50      }
51  
52      /**
53       * The group ID of the project to exclude.
54       *
55       * @return a {@code String}
56       */
57      public String getGroupId() {
58          return this.groupId;
59      }
60  
61      /**
62       * The artifact ID of the project to exclude.
63       *
64       * @return a {@code String}
65       */
66      public String getArtifactId() {
67          return this.artifactId;
68      }
69  
70      /**
71       * Gets the location of the specified field in the input source.
72       */
73      public InputLocation getLocation(Object key) {
74          return locations != null ? locations.get(key) : null;
75      }
76  
77      /**
78       * Creates a new builder with this object as the basis.
79       *
80       * @return a {@code Builder}
81       */
82      @Nonnull
83      public Builder with() {
84          return newBuilder(this);
85      }
86      /**
87       * Creates a new {@code Exclusion} instance using the specified groupId.
88       *
89       * @param groupId the new {@code String} to use
90       * @return a {@code Exclusion} with the specified groupId
91       */
92      @Nonnull
93      public Exclusion withGroupId(String groupId) {
94          return newBuilder(this, true).groupId(groupId).build();
95      }
96      /**
97       * Creates a new {@code Exclusion} instance using the specified artifactId.
98       *
99       * @param artifactId the new {@code String} to use
100      * @return a {@code Exclusion} with the specified artifactId
101      */
102     @Nonnull
103     public Exclusion withArtifactId(String artifactId) {
104         return newBuilder(this, true).artifactId(artifactId).build();
105     }
106 
107     /**
108      * Creates a new {@code Exclusion} instance.
109      * Equivalent to {@code newInstance(true)}.
110      * @see #newInstance(boolean)
111      *
112      * @return a new {@code Exclusion}
113      */
114     @Nonnull
115     public static Exclusion newInstance() {
116         return newInstance(true);
117     }
118 
119     /**
120      * Creates a new {@code Exclusion} instance using default values or not.
121      * Equivalent to {@code newBuilder(withDefaults).build()}.
122      *
123      * @param withDefaults the boolean indicating whether default values should be used
124      * @return a new {@code Exclusion}
125      */
126     @Nonnull
127     public static Exclusion newInstance(boolean withDefaults) {
128         return newBuilder(withDefaults).build();
129     }
130 
131     /**
132      * Creates a new {@code Exclusion} builder instance.
133      * Equivalent to {@code newBuilder(true)}.
134      * @see #newBuilder(boolean)
135      *
136      * @return a new {@code Builder}
137      */
138     @Nonnull
139     public static Builder newBuilder() {
140         return newBuilder(true);
141     }
142 
143     /**
144      * Creates a new {@code Exclusion} builder instance using default values or not.
145      *
146      * @param withDefaults the boolean indicating whether default values should be used
147      * @return a new {@code Builder}
148      */
149     @Nonnull
150     public static Builder newBuilder(boolean withDefaults) {
151         return new Builder(withDefaults);
152     }
153 
154     /**
155      * Creates a new {@code Exclusion} builder instance using the specified object as a basis.
156      * Equivalent to {@code newBuilder(from, false)}.
157      *
158      * @param from the {@code Exclusion} instance to use as a basis
159      * @return a new {@code Builder}
160      */
161     @Nonnull
162     public static Builder newBuilder(Exclusion from) {
163         return newBuilder(from, false);
164     }
165 
166     /**
167      * Creates a new {@code Exclusion} builder instance using the specified object as a basis.
168      *
169      * @param from the {@code Exclusion} instance to use as a basis
170      * @param forceCopy the boolean indicating if a copy should be forced
171      * @return a new {@code Builder}
172      */
173     @Nonnull
174     public static Builder newBuilder(Exclusion from, boolean forceCopy) {
175         return new Builder(from, forceCopy);
176     }
177 
178     /**
179      * Builder class used to create Exclusion instances.
180      * @see #with()
181      * @see #newBuilder()
182      */
183     @NotThreadSafe
184     public static class Builder
185     {
186         Exclusion base;
187         String groupId;
188         String artifactId;
189         Map<Object, InputLocation> locations;
190 
191         Builder(boolean withDefaults) {
192             if (withDefaults) {
193             }
194         }
195 
196         Builder(Exclusion base, boolean forceCopy) {
197             if (forceCopy) {
198                 this.groupId = base.groupId;
199                 this.artifactId = base.artifactId;
200                 this.locations = base.locations;
201             } else {
202                 this.base = base;
203             }
204         }
205 
206         @Nonnull
207         public Builder groupId(String groupId) {
208             this.groupId = groupId;
209             return this;
210         }
211 
212         @Nonnull
213         public Builder artifactId(String artifactId) {
214             this.artifactId = artifactId;
215             return this;
216         }
217 
218 
219         @Nonnull
220         public Builder location(Object key, InputLocation location) {
221             if (location != null) {
222                 if (!(this.locations instanceof HashMap)) {
223                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
224                 }
225                 this.locations.put(key, location);
226             }
227             return this;
228         }
229 
230         @Nonnull
231         public Exclusion build() {
232             if (base != null
233                     && (groupId == null || groupId == base.groupId)
234                     && (artifactId == null || artifactId == base.artifactId)
235             ) {
236                 return base;
237             }
238             Map<Object, InputLocation> locations = null;
239             InputLocation location = null;
240             InputLocation groupIdLocation = null;
241             InputLocation artifactIdLocation = null;
242             if (this.locations != null) {
243                 locations = this.locations;
244             }
245             return new Exclusion(
246                 groupId != null ? groupId : (base != null ? base.groupId : null),
247                 artifactId != null ? artifactId : (base != null ? base.artifactId : null),
248                 locations != null ? locations : (base != null ? base.locations : null)
249             );
250         }
251     }
252 
253 }