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