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