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.cli.internal.extension.model;
6   
7   import java.io.Serializable;
8   import java.util.ArrayList;
9   import java.util.Collection;
10  import java.util.Collections;
11  import java.util.HashMap;
12  import java.util.List;
13  import java.util.Map;
14  import org.apache.maven.api.annotations.Experimental;
15  import org.apache.maven.api.annotations.Generated;
16  import org.apache.maven.api.annotations.Immutable;
17  import org.apache.maven.api.annotations.Nonnull;
18  import org.apache.maven.api.annotations.NotThreadSafe;
19  import org.apache.maven.api.annotations.ThreadSafe;
20  
21  /**
22   * Extensions to load.
23   */
24  @Experimental
25  @Generated @ThreadSafe @Immutable
26  public class CoreExtensions
27      implements Serializable
28  {
29      final String namespaceUri;
30      final String modelEncoding;
31      /**
32       * A set of build extensions to use from this project.
33       */
34      final List<CoreExtension> extensions;
35  
36      /**
37        * Constructor for this class, package protected.
38        * @see Builder#build()
39        */
40      CoreExtensions(
41          String namespaceUri,
42          String modelEncoding,
43          Collection<CoreExtension> extensions
44      ) {
45          this.namespaceUri = namespaceUri;
46          this.modelEncoding = modelEncoding;
47          this.extensions = ImmutableCollections.copy(extensions);
48      }
49  
50      public String getNamespaceUri() {
51          return namespaceUri;
52      }
53  
54      public String getModelEncoding() {
55          return modelEncoding;
56      }
57  
58      /**
59       * A set of build extensions to use from this project.
60       *
61       * @return a {@code List<CoreExtension>}
62       */
63      @Nonnull
64      public List<CoreExtension> getExtensions() {
65          return this.extensions;
66      }
67  
68      /**
69       * Creates a new builder with this object as the basis.
70       *
71       * @return a {@code Builder}
72       */
73      @Nonnull
74      public Builder with() {
75          return newBuilder(this);
76      }
77      /**
78       * Creates a new {@code CoreExtensions} instance using the specified extensions.
79       *
80       * @param extensions the new {@code Collection<CoreExtension>} to use
81       * @return a {@code CoreExtensions} with the specified extensions
82       */
83      @Nonnull
84      public CoreExtensions withExtensions(Collection<CoreExtension> extensions) {
85          return newBuilder(this, true).extensions(extensions).build();
86      }
87  
88      /**
89       * Creates a new {@code CoreExtensions} instance.
90       * Equivalent to {@code newInstance(true)}.
91       * @see #newInstance(boolean)
92       *
93       * @return a new {@code CoreExtensions}
94       */
95      @Nonnull
96      public static CoreExtensions newInstance() {
97          return newInstance(true);
98      }
99  
100     /**
101      * Creates a new {@code CoreExtensions} instance using default values or not.
102      * Equivalent to {@code newBuilder(withDefaults).build()}.
103      *
104      * @param withDefaults the boolean indicating whether default values should be used
105      * @return a new {@code CoreExtensions}
106      */
107     @Nonnull
108     public static CoreExtensions newInstance(boolean withDefaults) {
109         return newBuilder(withDefaults).build();
110     }
111 
112     /**
113      * Creates a new {@code CoreExtensions} builder instance.
114      * Equivalent to {@code newBuilder(true)}.
115      * @see #newBuilder(boolean)
116      *
117      * @return a new {@code Builder}
118      */
119     @Nonnull
120     public static Builder newBuilder() {
121         return newBuilder(true);
122     }
123 
124     /**
125      * Creates a new {@code CoreExtensions} builder instance using default values or not.
126      *
127      * @param withDefaults the boolean indicating whether default values should be used
128      * @return a new {@code Builder}
129      */
130     @Nonnull
131     public static Builder newBuilder(boolean withDefaults) {
132         return new Builder(withDefaults);
133     }
134 
135     /**
136      * Creates a new {@code CoreExtensions} builder instance using the specified object as a basis.
137      * Equivalent to {@code newBuilder(from, false)}.
138      *
139      * @param from the {@code CoreExtensions} instance to use as a basis
140      * @return a new {@code Builder}
141      */
142     @Nonnull
143     public static Builder newBuilder(CoreExtensions from) {
144         return newBuilder(from, false);
145     }
146 
147     /**
148      * Creates a new {@code CoreExtensions} builder instance using the specified object as a basis.
149      *
150      * @param from the {@code CoreExtensions} instance to use as a basis
151      * @param forceCopy the boolean indicating if a copy should be forced
152      * @return a new {@code Builder}
153      */
154     @Nonnull
155     public static Builder newBuilder(CoreExtensions from, boolean forceCopy) {
156         return new Builder(from, forceCopy);
157     }
158 
159     /**
160      * Builder class used to create CoreExtensions instances.
161      * @see #with()
162      * @see #newBuilder()
163      */
164     @NotThreadSafe
165     public static class Builder
166     {
167         CoreExtensions base;
168         String namespaceUri;
169         String modelEncoding;
170         Collection<CoreExtension> extensions;
171 
172         Builder(boolean withDefaults) {
173             if (withDefaults) {
174             }
175         }
176 
177         Builder(CoreExtensions base, boolean forceCopy) {
178             this.namespaceUri = base.namespaceUri;
179             this.modelEncoding = base.modelEncoding;
180             if (forceCopy) {
181                 this.extensions = base.extensions;
182             } else {
183                 this.base = base;
184             }
185         }
186 
187         @Nonnull
188         public Builder namespaceUri(String namespaceUri) {
189             this.namespaceUri = namespaceUri;
190             return this;
191         }
192 
193         @Nonnull
194         public Builder modelEncoding(String modelEncoding) {
195             this.modelEncoding = modelEncoding;
196             return this;
197         }
198 
199         @Nonnull
200         public Builder extensions(Collection<CoreExtension> extensions) {
201             this.extensions = extensions;
202             return this;
203         }
204 
205 
206         @Nonnull
207         public CoreExtensions build() {
208             if (base != null
209                     && (extensions == null || extensions == base.extensions)
210             ) {
211                 return base;
212             }
213             return new CoreExtensions(
214                 namespaceUri != null ? namespaceUri : (base != null ? base.namespaceUri : ""),
215                 modelEncoding != null ? modelEncoding : (base != null ? base.modelEncoding : "UTF-8"),
216                 extensions != null ? extensions : (base != null ? base.extensions : null)
217             );
218         }
219     }
220 
221 }