Package adams.core.option.constraint
Class StringLength
- java.lang.Object
-
- adams.core.option.constraint.AbstractOptionConstraint<String>
-
- adams.core.option.constraint.StringLength
-
- All Implemented Interfaces:
Serializable
public class StringLength extends AbstractOptionConstraint<String>
Constraint for enforcing min/max length of strings.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description StringLength(AbstractOption owner, Integer min, Integer max)Initializes the constraint.StringLength(Integer min, Integer max)Initializes the constraint.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description IntegergetMax()Returns the upper limit, if any.IntegergetMin()Returns the lower limit, if any.booleanhasMax()Returns whether an upper limit is set.booleanhasMin()Returns whether a lower limit is set.StringisValidMsg(String value)Checks the value against the constraints.-
Methods inherited from class adams.core.option.constraint.AbstractOptionConstraint
getOptionHandler, getOptionManager, getOwner, isValid, logMsg, setOwner
-
-
-
-
Constructor Detail
-
StringLength
public StringLength(Integer min, Integer max)
Initializes the constraint.- Parameters:
min- the minimum length, null for no limitmax- the maximum length, null for no limit
-
StringLength
public StringLength(AbstractOption owner, Integer min, Integer max)
Initializes the constraint.- Parameters:
owner- the option this constraint is formin- the minimum length, null for no limitmax- the maximum length, null for no limit
-
-
Method Detail
-
hasMin
public boolean hasMin()
Returns whether a lower limit is set.- Returns:
- true if limit set
-
getMin
public Integer getMin()
Returns the lower limit, if any.- Returns:
- the limit, null if no limit
-
hasMax
public boolean hasMax()
Returns whether an upper limit is set.- Returns:
- true if limit set
-
getMax
public Integer getMax()
Returns the upper limit, if any.- Returns:
- the limit, null if no limit
-
isValidMsg
public String isValidMsg(String value)
Checks the value against the constraints. If it violates the constraints, uses the owner's logger to output a warning message.- Specified by:
isValidMsgin classAbstractOptionConstraint<String>- Parameters:
value- the value to check- Returns:
- null if valid otherwise the error message
-
-