Module com.github.rvesse.airline
Class LengthRestriction
java.lang.Object
com.github.rvesse.airline.restrictions.AbstractCommonRestriction
com.github.rvesse.airline.restrictions.common.AbstractStringRestriction
com.github.rvesse.airline.restrictions.common.LengthRestriction
- All Implemented Interfaces:
HelpHint
,ArgumentsRestriction
,OptionRestriction
A restriction that requires string values meet length constraints
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionLengthRestriction
(int length, boolean maximum) Creates a length restriction with either a minimum or maximumLengthRestriction
(int min, int max) Creates a length restriction with a minimum and maximum i.e. -
Method Summary
Modifier and TypeMethodDescriptionString[]
getContentBlock
(int blockNumber) Gets the content block with the given numberGets the format of the provided help informationGets the preamble text that should be includedprotected boolean
Method that derived classes must implement to check whether a value is validint
Gets the number of content blocks providedprotected <T> ParseRestrictionViolatedException
violated
(ParseState<T> state, ArgumentsMetadata arguments, String value) Method that derived classes must implement to provide an exception for the case of an invalid argument value, this will be called ifAbstractStringRestriction.isValid(String)
returnsfalse
protected <T> ParseRestrictionViolatedException
violated
(ParseState<T> state, OptionMetadata option, String value) Method that derived classes must implement to provide an exception for the case of an invalid option value, this will be called ifAbstractStringRestriction.isValid(String)
returnsfalse
Methods inherited from class com.github.rvesse.airline.restrictions.common.AbstractStringRestriction
preValidate, preValidate
Methods inherited from class com.github.rvesse.airline.restrictions.AbstractCommonRestriction
finalValidate, finalValidate, getArgumentTitle, getArgumentTitle, getOptionTitle, postValidate, postValidate
-
Field Details
-
maximum
private final boolean maximum -
range
private final boolean range -
min
private final int min -
max
private final int max
-
-
Constructor Details
-
LengthRestriction
public LengthRestriction(int length, boolean maximum) Creates a length restriction with either a minimum or maximum- Parameters:
length
- Lengthmaximum
- True if thelength
is a maximum, false if it is a minimum
-
LengthRestriction
public LengthRestriction(int min, int max) Creates a length restriction with a minimum and maximum i.e. a range- Parameters:
min
- Minimum lengthmax
- Maximum length
-
-
Method Details
-
isValid
Description copied from class:AbstractStringRestriction
Method that derived classes must implement to check whether a value is valid- Specified by:
isValid
in classAbstractStringRestriction
- Parameters:
value
- Value- Returns:
- True if valid, false if valid
-
violated
protected <T> ParseRestrictionViolatedException violated(ParseState<T> state, OptionMetadata option, String value) Description copied from class:AbstractStringRestriction
Method that derived classes must implement to provide an exception for the case of an invalid option value, this will be called ifAbstractStringRestriction.isValid(String)
returnsfalse
- Specified by:
violated
in classAbstractStringRestriction
- Parameters:
state
- Parser stateoption
- Option metadata for the option whose value is being checkedvalue
- Value which has been deemed invalid- Returns:
- Exception
-
violated
protected <T> ParseRestrictionViolatedException violated(ParseState<T> state, ArgumentsMetadata arguments, String value) Description copied from class:AbstractStringRestriction
Method that derived classes must implement to provide an exception for the case of an invalid argument value, this will be called ifAbstractStringRestriction.isValid(String)
returnsfalse
- Specified by:
violated
in classAbstractStringRestriction
- Parameters:
state
- Parser statearguments
- Arguments metadatavalue
- Value which has been deemed invalid- Returns:
- Exception
-
getPreamble
Description copied from interface:HelpHint
Gets the preamble text that should be included- Specified by:
getPreamble
in interfaceHelpHint
- Returns:
- Preamble text
-
getFormat
Description copied from interface:HelpHint
Gets the format of the provided help information -
numContentBlocks
public int numContentBlocks()Description copied from interface:HelpHint
Gets the number of content blocks providedHelp generators should consult the
HelpHint.getFormat()
return value to determine how to format the content blocks but they are not required to do so- Specified by:
numContentBlocks
in interfaceHelpHint
- Returns:
- Number of content blocks
-
getContentBlock
Description copied from interface:HelpHint
Gets the content block with the given number- Specified by:
getContentBlock
in interfaceHelpHint
- Parameters:
blockNumber
- Block number- Returns:
- Content Block
-