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