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