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