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.settings;
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   * common base class that contains code to track the source for
20   * this instance (USER|GLOBAL)
21   */
22  @Experimental
23  @Generated @ThreadSafe @Immutable
24  public class TrackableBase
25      implements Serializable, InputLocationTracker
26  {
27      /** Locations */
28      final Map<Object, InputLocation> locations;
29  
30      /**
31        * Constructor for this class, package protected.
32        * @see Builder#build()
33        */
34      TrackableBase(
35          Map<Object, InputLocation> locations
36      ) {
37          this.locations = ImmutableCollections.copy(locations);
38      }
39  
40      /**
41       * Gets the location of the specified field in the input source.
42       */
43      public InputLocation getLocation(Object key) {
44          return locations != null ? locations.get(key) : null;
45      }
46  
47      /**
48       * Creates a new builder with this object as the basis.
49       *
50       * @return a {@code Builder}
51       */
52      @Nonnull
53      public Builder with() {
54          return newBuilder(this);
55      }
56  
57      /**
58       * Creates a new {@code TrackableBase} instance.
59       * Equivalent to {@code newInstance(true)}.
60       * @see #newInstance(boolean)
61       *
62       * @return a new {@code TrackableBase}
63       */
64      @Nonnull
65      public static TrackableBase newInstance() {
66          return newInstance(true);
67      }
68  
69      /**
70       * Creates a new {@code TrackableBase} instance using default values or not.
71       * Equivalent to {@code newBuilder(withDefaults).build()}.
72       *
73       * @param withDefaults the boolean indicating whether default values should be used
74       * @return a new {@code TrackableBase}
75       */
76      @Nonnull
77      public static TrackableBase newInstance(boolean withDefaults) {
78          return newBuilder(withDefaults).build();
79      }
80  
81      /**
82       * Creates a new {@code TrackableBase} builder instance.
83       * Equivalent to {@code newBuilder(true)}.
84       * @see #newBuilder(boolean)
85       *
86       * @return a new {@code Builder}
87       */
88      @Nonnull
89      public static Builder newBuilder() {
90          return newBuilder(true);
91      }
92  
93      /**
94       * Creates a new {@code TrackableBase} builder instance using default values or not.
95       *
96       * @param withDefaults the boolean indicating whether default values should be used
97       * @return a new {@code Builder}
98       */
99      @Nonnull
100     public static Builder newBuilder(boolean withDefaults) {
101         return new Builder(withDefaults);
102     }
103 
104     /**
105      * Creates a new {@code TrackableBase} builder instance using the specified object as a basis.
106      * Equivalent to {@code newBuilder(from, false)}.
107      *
108      * @param from the {@code TrackableBase} instance to use as a basis
109      * @return a new {@code Builder}
110      */
111     @Nonnull
112     public static Builder newBuilder(TrackableBase from) {
113         return newBuilder(from, false);
114     }
115 
116     /**
117      * Creates a new {@code TrackableBase} builder instance using the specified object as a basis.
118      *
119      * @param from the {@code TrackableBase} instance to use as a basis
120      * @param forceCopy the boolean indicating if a copy should be forced
121      * @return a new {@code Builder}
122      */
123     @Nonnull
124     public static Builder newBuilder(TrackableBase from, boolean forceCopy) {
125         return new Builder(from, forceCopy);
126     }
127 
128     /**
129      * Builder class used to create TrackableBase instances.
130      * @see #with()
131      * @see #newBuilder()
132      */
133     @NotThreadSafe
134     public static class Builder
135     {
136         TrackableBase base;
137         Map<Object, InputLocation> locations;
138 
139         Builder(boolean withDefaults) {
140             if (withDefaults) {
141             }
142         }
143 
144         Builder(TrackableBase base, boolean forceCopy) {
145             if (forceCopy) {
146                 this.locations = base.locations;
147             } else {
148                 this.base = base;
149             }
150         }
151 
152 
153         @Nonnull
154         public Builder location(Object key, InputLocation location) {
155             if (location != null) {
156                 if (!(this.locations instanceof HashMap)) {
157                     this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
158                 }
159                 this.locations.put(key, location);
160             }
161             return this;
162         }
163 
164         @Nonnull
165         public TrackableBase build() {
166             if (base != null
167             ) {
168                 return base;
169             }
170             Map<Object, InputLocation> newlocs = this.locations != null ? this.locations : Collections.emptyMap();
171             Map<Object, InputLocation> oldlocs = this.base != null && this.base.locations != null ? this.base.locations : Collections.emptyMap();
172             Map<Object, InputLocation> locations = new HashMap<>();
173             locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
174             return new TrackableBase(
175                 locations
176             );
177         }
178     }
179 
180 
181             
182     public static final String USER_LEVEL = "user-level";
183     public static final String PROJECT_LEVEL = "project-level";
184     public static final String GLOBAL_LEVEL = "global-level";
185 
186     private String sourceLevel = USER_LEVEL;
187     private boolean sourceLevelSet = false;
188 
189     public void setSourceLevel( String sourceLevel )
190     {
191         if ( sourceLevelSet )
192         {
193             throw new IllegalStateException( "Cannot reset sourceLevel attribute; it is already set to: " + sourceLevel );
194         }
195         else if ( !( USER_LEVEL.equals( sourceLevel ) || PROJECT_LEVEL.equals( sourceLevel )  || GLOBAL_LEVEL.equals( sourceLevel ) ) )
196         {
197             throw new IllegalArgumentException( "sourceLevel must be one of: {" + USER_LEVEL + "," + PROJECT_LEVEL + "," + GLOBAL_LEVEL + "}" );
198         }
199         else
200         {
201             this.sourceLevel = sourceLevel;
202             this.sourceLevelSet = true;
203         }
204     }
205 
206     public String getSourceLevel()
207     {
208         return sourceLevel;
209     }
210             
211           
212 }