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   * Base class for <code>Mirror</code>, <code>Profile</code>, <code>Proxy</code> and <code>Server</code>.
20   */
21  @Experimental
22  @Generated @ThreadSafe @Immutable
23  public class IdentifiableBase
24      extends TrackableBase
25      implements Serializable
26  {
27      /**
28       */
29      final String id;
30  
31      /**
32        * Constructor for this class, package protected.
33        * @see Builder#build()
34        */
35      IdentifiableBase(
36          String id
37      )
38      {
39          super(
40          );
41          this.id = id;
42      }
43  
44      /**
45       *
46       * @return a {@code String}
47       */
48      public String getId()
49      {
50          return this.id;
51      }
52  
53      /**
54       * Creates a new builder with this object as the basis.
55       *
56       * @return a {@code Builder}
57       */
58      @Nonnull
59      public Builder with()
60      {
61          return newBuilder( this );
62      }
63      /**
64       * Creates a new {@code IdentifiableBase} instance using the specified id.
65       *
66       * @param id the new {@code String} to use
67       * @return a {@code IdentifiableBase} with the specified id
68       */
69      @Nonnull
70      public IdentifiableBase withId( String id )
71      {
72          return with().id( id ).build();
73      }
74  
75      /**
76       * Creates a new {@code IdentifiableBase} instance.
77       * Equivalent to {@code newInstance( true )}.
78       * @see #newInstance(boolean)
79       *
80       * @return a new {@code IdentifiableBase}
81       */
82      @Nonnull
83      public static IdentifiableBase newInstance()
84      {
85          return newInstance( true );
86      }
87  
88      /**
89       * Creates a new {@code IdentifiableBase} instance using default values or not.
90       * Equivalent to {@code newBuilder( withDefaults ).build()}.
91       *
92       * @param withDefaults the boolean indicating whether default values should be used
93       * @return a new {@code IdentifiableBase}
94       */
95      @Nonnull
96      public static IdentifiableBase newInstance( boolean withDefaults )
97      {
98          return newBuilder( withDefaults ).build();
99      }
100 
101     /**
102      * Creates a new {@code IdentifiableBase} builder instance.
103      * Equivalent to {@code newBuilder( true )}.
104      * @see #newBuilder(boolean)
105      *
106      * @return a new {@code Builder}
107      */
108     @Nonnull
109     public static Builder newBuilder()
110     {
111         return newBuilder( true );
112     }
113 
114     /**
115      * Creates a new {@code IdentifiableBase} builder instance using default values or not.
116      *
117      * @param withDefaults the boolean indicating whether default values should be used
118      * @return a new {@code Builder}
119      */
120     @Nonnull
121     public static Builder newBuilder( boolean withDefaults )
122     {
123         return new Builder( withDefaults );
124     }
125 
126     /**
127      * Creates a new {@code IdentifiableBase} builder instance using the specified object as a basis.
128      * Equivalent to {@code newBuilder( from, false )}.
129      *
130      * @param from the {@code IdentifiableBase} instance to use as a basis
131      * @return a new {@code Builder}
132      */
133     @Nonnull
134     public static Builder newBuilder( IdentifiableBase from )
135     {
136         return newBuilder( from, false );
137     }
138 
139     /**
140      * Creates a new {@code IdentifiableBase} builder instance using the specified object as a basis.
141      *
142      * @param from the {@code IdentifiableBase} instance to use as a basis
143      * @param forceCopy the boolean indicating if a copy should be forced
144      * @return a new {@code Builder}
145      */
146     @Nonnull
147     public static Builder newBuilder( IdentifiableBase from, boolean forceCopy )
148     {
149         return new Builder( from, forceCopy );
150     }
151 
152     /**
153      * Builder class used to create IdentifiableBase instances.
154      * @see #with()
155      * @see #newBuilder()
156      */
157     @NotThreadSafe
158     public static class Builder
159         extends TrackableBase.Builder
160     {
161         IdentifiableBase base;
162         String id;
163 
164         Builder( boolean withDefaults )
165         {
166             super( withDefaults );
167             if ( withDefaults )
168             {
169                 this.id = "default";
170             }
171         }
172 
173         Builder( IdentifiableBase base, boolean forceCopy )
174         {
175             super( base, forceCopy );
176             if ( forceCopy )
177             {
178                 this.id = base.id;
179             }
180             else
181             {
182                 this.base = base;
183             }
184         }
185 
186         @Nonnull
187         public Builder id( String id )
188         {
189             this.id = id;
190             return this;
191         }
192 
193 
194         @Nonnull
195         public IdentifiableBase build()
196         {
197             if ( base != null
198                     && ( id == null || id == base.id )
199             )
200             {
201                 return base;
202             }
203             return new IdentifiableBase(
204                 id != null ? id : ( base != null ? base.id : null )
205             );
206         }
207     }
208 
209 }