Skip to content

Commit 34d6a46

Browse files
committed
feat: rename mandatory to required
Signed-off-by: Nico-DF <[email protected]>
1 parent 8a2d042 commit 34d6a46

File tree

8 files changed

+38
-38
lines changed

8 files changed

+38
-38
lines changed

spring-shell-core/src/main/java/org/springframework/shell/core/tui/component/StringInput.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class StringInput extends AbstractTextComponent<String, StringInputContex
4949

5050
private @Nullable Character maskCharacter;
5151

52-
private boolean mandatory;
52+
private boolean required;
5353

5454
public StringInput(Terminal terminal) {
5555
this(terminal, null, null, null, false);
@@ -65,12 +65,12 @@ public StringInput(Terminal terminal, @Nullable String name, @Nullable String de
6565
}
6666

6767
public StringInput(Terminal terminal, @Nullable String name, @Nullable String defaultValue,
68-
@Nullable Function<StringInputContext, List<AttributedString>> renderer, boolean mandatory) {
68+
@Nullable Function<StringInputContext, List<AttributedString>> renderer, boolean required) {
6969
super(terminal, name, null);
7070
setRenderer(renderer != null ? renderer : new DefaultRenderer());
7171
setTemplateLocation("classpath:org/springframework/shell/component/string-input-default.stg");
7272
this.defaultValue = defaultValue;
73-
this.mandatory = mandatory;
73+
this.required = required;
7474
}
7575

7676
/**
@@ -82,20 +82,20 @@ public void setMaskCharacter(@Nullable Character maskCharacter) {
8282
}
8383

8484
/**
85-
* Sets a mandatory flag to check that the result is not empty
85+
* Sets a required flag to check that the result is not empty
8686
*
87-
* @param mandatory if input is required
87+
* @param required if input is required
8888
*/
89-
public void setMandatory(boolean mandatory) {
90-
this.mandatory = mandatory;
89+
public void setRequired(boolean required) {
90+
this.required = required;
9191
}
9292

9393
@Override
9494
public StringInputContext getThisContext(@Nullable ComponentContext<?> context) {
9595
if (context != null && currentContext == context) {
9696
return currentContext;
9797
}
98-
currentContext = StringInputContext.of(defaultValue, maskCharacter, mandatory);
98+
currentContext = StringInputContext.of(defaultValue, maskCharacter, required);
9999
currentContext.setName(getName());
100100
if (context != null) {
101101
context.stream().forEach(e -> {
@@ -141,7 +141,7 @@ protected boolean read(BindingReader bindingReader, KeyMap<String> keyMap, Strin
141141
}
142142
else if (context.getDefaultValue() != null) {
143143
context.setResultValue(context.getDefaultValue());
144-
} else if (mandatory) {
144+
} else if (required) {
145145
context.setMessage("This field is mandatory", TextComponentContext.MessageLevel.ERROR);
146146
break;
147147
}
@@ -199,16 +199,16 @@ public interface StringInputContext extends TextComponentContext<String, StringI
199199
/**
200200
* Sets flag for mandatory input.
201201
*
202-
* @param mandatory true if input is mandatory
202+
* @param required true if input is required
203203
*/
204-
void setMandatory(boolean mandatory);
204+
void setRequired(boolean required);
205205

206206
/**
207207
* Returns flag if input is required.
208208
*
209209
* @return true if input is required, false otherwise
210210
*/
211-
boolean isMandatory();
211+
boolean isRequired();
212212

213213
/**
214214
* Gets an empty {@link StringInputContext}.
@@ -231,8 +231,8 @@ public static StringInputContext of(@Nullable String defaultValue, @Nullable Cha
231231
*
232232
* @return path input context
233233
*/
234-
public static StringInputContext of(@Nullable String defaultValue, @Nullable Character maskCharacter, boolean mandatory) {
235-
return new DefaultStringInputContext(defaultValue, maskCharacter, mandatory);
234+
public static StringInputContext of(@Nullable String defaultValue, @Nullable Character maskCharacter, boolean required) {
235+
return new DefaultStringInputContext(defaultValue, maskCharacter, required);
236236
}
237237

238238
}
@@ -244,12 +244,12 @@ private static class DefaultStringInputContext extends BaseTextComponentContext<
244244

245245
private @Nullable Character maskCharacter;
246246

247-
private boolean mandatory;
247+
private boolean required;
248248

249-
public DefaultStringInputContext(@Nullable String defaultValue, @Nullable Character maskCharacter, boolean mandatory) {
249+
public DefaultStringInputContext(@Nullable String defaultValue, @Nullable Character maskCharacter, boolean required) {
250250
this.defaultValue = defaultValue;
251251
this.maskCharacter = maskCharacter;
252-
this.mandatory = mandatory;
252+
this.required = required;
253253
}
254254

255255
@Override
@@ -268,8 +268,8 @@ public void setMaskCharacter(Character maskCharacter) {
268268
}
269269

270270
@Override
271-
public void setMandatory(boolean mandatory) {
272-
this.mandatory = mandatory;
271+
public void setRequired(boolean required) {
272+
this.required = required;
273273
}
274274

275275
@Override
@@ -293,8 +293,8 @@ public boolean hasMaskCharacter() {
293293
}
294294

295295
@Override
296-
public boolean isMandatory() {
297-
return mandatory;
296+
public boolean isRequired() {
297+
return required;
298298
}
299299

300300
@Override
@@ -305,7 +305,7 @@ public boolean isMandatory() {
305305
attributes.put("maskedResultValue", getMaskedResultValue());
306306
attributes.put("maskCharacter", getMaskCharacter());
307307
attributes.put("hasMaskCharacter", hasMaskCharacter());
308-
attributes.put("mandatory", isMandatory());
308+
attributes.put("required", isRequired());
309309
Map<String, Object> model = new HashMap<>();
310310
model.put("model", attributes);
311311
return model;

spring-shell-core/src/main/java/org/springframework/shell/core/tui/component/flow/BaseStringInput.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public abstract class BaseStringInput extends BaseInput<StringInputSpec> impleme
4545

4646
private @Nullable Character maskCharacter;
4747

48-
private boolean mandatory = false;
48+
private boolean required = false;
4949

5050
private @Nullable Function<StringInputContext, List<AttributedString>> renderer;
5151

@@ -94,8 +94,8 @@ public StringInputSpec maskCharacter(Character maskCharacter) {
9494
}
9595

9696
@Override
97-
public StringInputSpec mandatory() {
98-
this.mandatory = true;
97+
public StringInputSpec required() {
98+
this.required = true;
9999
return this;
100100
}
101101

@@ -166,8 +166,8 @@ public StringInputSpec getThis() {
166166
return maskCharacter;
167167
}
168168

169-
public boolean isMandatory() {
170-
return mandatory;
169+
public boolean isRequired() {
170+
return required;
171171
}
172172

173173
public @Nullable Function<StringInputContext, List<AttributedString>> getRenderer() {

spring-shell-core/src/main/java/org/springframework/shell/core/tui/component/flow/ComponentFlow.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ else if (n.isPresent()) {
468468

469469
private Stream<OrderedInputOperation> stringInputsStream() {
470470
return stringInputs.stream().map(input -> {
471-
StringInput selector = new StringInput(terminal, input.getName(), input.getDefaultValue(), null, input.isMandatory());
471+
StringInput selector = new StringInput(terminal, input.getName(), input.getDefaultValue(), null, input.isRequired());
472472
Function<ComponentContext<?>, ComponentContext<?>> operation = (context) -> {
473473
if (input.getResultMode() == ResultMode.ACCEPT && input.isStoreResult()
474474
&& StringUtils.hasText(input.getResultValue())) {
@@ -492,7 +492,7 @@ private Stream<OrderedInputOperation> stringInputsStream() {
492492
if (input.getResultMode() == ResultMode.VERIFY && StringUtils.hasText(input.getResultValue())) {
493493
selector.addPreRunHandler(c -> {
494494
c.setDefaultValue(input.getResultValue());
495-
c.setMandatory(input.isMandatory());
495+
c.setRequired(input.isRequired());
496496
});
497497
}
498498
selector.addPostRunHandler(c -> {

spring-shell-core/src/main/java/org/springframework/shell/core/tui/component/flow/StringInputSpec.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ public interface StringInputSpec extends BaseInputSpec<StringInputSpec> {
6868
StringInputSpec maskCharacter(Character maskCharacter);
6969

7070
/**
71-
* Sets input to mandatory
71+
* Sets input to required
7272
*
7373
* @return a builder
7474
*/
75-
StringInputSpec mandatory();
75+
StringInputSpec required();
7676

7777
/**
7878
* Sets a renderer function.

spring-shell-core/src/test/java/org/springframework/shell/core/tui/component/StringInputTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ void testResultMandatoryInput() {
168168
StringInput component1 = new StringInput(getTerminal());
169169
component1.setResourceLoader(new DefaultResourceLoader());
170170
component1.setTemplateExecutor(getTemplateExecutor());
171-
component1.setMandatory(true);
171+
component1.setRequired(true);
172172

173173
service.execute(() -> {
174174
StringInputContext run1Context = component1.run(empty);

spring-shell-core/src/test/java/org/springframework/shell/core/tui/component/flow/ComponentFlowTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void testSimpleFlow() {
5656
.and()
5757
.withStringInput("field3")
5858
.name("Field3")
59-
.mandatory()
59+
.required()
6060
.and()
6161
.withPathInput("path1")
6262
.name("Path1")

spring-shell-core/src/test/resources/org/springframework/shell/component/string-input-default.stg

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ info(model) ::= <%
1515
<if(model.maskedInput)>
1616
<model.maskedInput>
1717
<else>
18-
<if(model.mandatory)>
19-
<("[Mandatory]"); format="style-value">
18+
<if(model.required)>
19+
<("[Required]"); format="style-value">
2020
<endif>
2121
<if(model.defaultValue)>
2222
<("[Default "); format="style-value"><model.defaultValue; format="style-value"><("]"); format="style-value">
@@ -26,8 +26,8 @@ info(model) ::= <%
2626
<if(model.input)>
2727
<model.input>
2828
<else>
29-
<if(model.mandatory)>
30-
<("[Mandatory]"); format="style-value">
29+
<if(model.required)>
30+
<("[Required]"); format="style-value">
3131
<endif>
3232
<if(model.defaultValue)>
3333
<("[Default "); format="style-value"><model.defaultValue; format="style-value"><("]"); format="style-value">

spring-shell-docs/modules/ROOT/pages/components/ui/stringinput.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ The context object is `StringInputContext`. The following table lists its contex
4141
|`hasMaskCharacter`
4242
|`true` if a mask character is set. Otherwise, false.
4343

44-
|`mandatory`
44+
|`required`
4545
|`true` if the input is required. Otherwise, false.
4646

4747
|`model`

0 commit comments

Comments
 (0)