java.lang.Object
dev.sympho.modular_commands.utils.builder.ParameterBuilder<T>
- Type Parameters:
T- The type of value received by the parameter.
Base for a parameter builder.
- Since:
- 1.0
- Version:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe default parameter value.protected @MonotonicNonNull @MatchesRegex("(?Us)^.{1,100}+$") StringThe parameter description.protected @MonotonicNonNull @MatchesRegex("(?U)^[-_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") StringThe parameter name.protected @MonotonicNonNull ArgumentParser<?,T> The parser to use for processing.protected booleanWhether the parameter is required. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new builder with default values.ParameterBuilder(ParameterBuilder<T> base) Constructs a new builder that is a copy of the given builder. -
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds the configured parameter.booleanIndicates whether the given object is a builder of the same type and configuration as this one.static <T extends @NonNull Object>
ParameterBuilder<T>Constructs a new builder that is initialized to make a copy of the given parameter.inthashCode()withDefault(@Nullable T defaultValue) Sets the default value of the parameter to build.withDescription(@MatchesRegex("(?Us)^.{1,100}+$") String description) Sets the description of the parameter to build.withName(@MatchesRegex("(?U)^[-_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") String name) Sets the name of the parameter to build.withParser(ArgumentParser<?, T> parser) Sets the parser to process arguments with.withRequired(boolean required) Sets the required flag of the parameter to build.
-
Field Details
-
name
protected @MonotonicNonNull @MatchesRegex("(?U)^[-_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") String nameThe parameter name. -
description
The parameter description. -
required
protected boolean requiredWhether the parameter is required. -
defaultValue
The default parameter value. -
parser
The parser to use for processing.
-
-
Constructor Details
-
ParameterBuilder
Constructs a new builder with default values. -
ParameterBuilder
Constructs a new builder that is a copy of the given builder.- Parameters:
base- The builder to copy.
-
-
Method Details
-
from
@SideEffectFree public static <T extends @NonNull Object> ParameterBuilder<T> from(Parameter<T> base) throws IllegalArgumentException Constructs a new builder that is initialized to make a copy of the given parameter.- Type Parameters:
T- The argument type.- Parameters:
base- The parameter to copy.- Returns:
- The initialized builder.
- Throws:
IllegalArgumentException- if the given parameter has invalid values.
-
withName
@Deterministic public ParameterBuilder<T> withName(@MatchesRegex("(?U)^[-_\\p{L}\\p{N}\\p{sc=Deva}\\p{sc=Thai}]{1,32}+$") String name) throws IllegalArgumentException Sets the name of the parameter to build.- Parameters:
name- The parameter name.- Returns:
- This builder.
- Throws:
IllegalArgumentException- if the given name is invalid.- See Also:
-
withDescription
@Deterministic public ParameterBuilder<T> withDescription(@MatchesRegex("(?Us)^.{1,100}+$") String description) throws IllegalArgumentException Sets the description of the parameter to build.- Parameters:
description- The parameter description.- Returns:
- This builder.
- Throws:
IllegalArgumentException- if the given name is invalid.- See Also:
-
withRequired
Sets the required flag of the parameter to build.- Parameters:
required- The required flag.- Returns:
- This builder.
- See Also:
-
withDefault
Sets the default value of the parameter to build.- Parameters:
defaultValue- The default value.- Returns:
- This builder.
- See Also:
-
withParser
Sets the parser to process arguments with.- Parameters:
parser- The parser to use.- Returns:
- This builder.
- See Also:
-
build
@SideEffectFree public Parameter<T> build(ParameterBuilder<T extends @NonNull Object> this) throws IllegalStateException Builds the configured parameter.- Returns:
- The built parameter.
- Throws:
IllegalStateException- if the current configuration is invalid.
-
equals
Indicates whether the given object is a builder of the same type and configuration as this one. -
hashCode
public int hashCode()
-