Class Flag
- java.lang.Object
-
- elki.utilities.optionhandling.parameters.AbstractParameter<Flag,java.lang.Boolean>
-
- elki.utilities.optionhandling.parameters.Flag
-
- All Implemented Interfaces:
Parameter<java.lang.Boolean>
public class Flag extends AbstractParameter<Flag,java.lang.Boolean>
Option class specifying a flag object.A flag object is optional parameter which can be set (value "true") or not (value "false").
- Since:
- 0.3
- Author:
- Steffi Wanka, Erich Schubert
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceFlag.BooleanConsumerRepresents an operation that accepts a singleboolean-valued argument and returns no result.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringNOT_SETConstant indicating that the flag is not set.static java.lang.StringSETConstant indicating that the flag is set.-
Fields inherited from class elki.utilities.optionhandling.parameters.AbstractParameter
constraints, defaultValue, givenValue, optionalParameter, optionid
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetSyntax()A flag has no syntax, since it doesn't take extra optionsjava.lang.StringgetValueAsString()Get the value as string.booleangrab(Parameterization config, Flag.BooleanConsumer consumer)Get the parameter.booleanisFalse()Shorthand forisDefined() && getValue() == falsebooleanisTrue()Shorthand forisDefined() && getValue() == trueprotected java.lang.BooleanparseValue(java.lang.Object obj)Parse a given value into the destination type.voidsetValue(boolean val)Convenience function using a native boolean, that doesn't require error handling.protected booleanvalidate(java.lang.Boolean obj)Validate a value after parsing (e.g., do constraint checks!)-
Methods inherited from class elki.utilities.optionhandling.parameters.AbstractParameter
addConstraint, describeValues, getConstraints, getDefaultValue, getDefaultValueAsString, getOptionID, getValue, hasDefaultValue, isDefined, isOptional, isValid, setDefaultValue, setOptional, setValue, setValueInternal, tookDefaultValue, tryDefaultValue
-
-
-
-
Field Detail
-
SET
public static final java.lang.String SET
Constant indicating that the flag is set.- See Also:
- Constant Field Values
-
NOT_SET
public static final java.lang.String NOT_SET
Constant indicating that the flag is not set.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Flag
public Flag(OptionID optionID)
Constructs a flag object with the given optionID.If the flag is not set its value is "false".
- Parameters:
optionID- the unique id of the option
-
-
Method Detail
-
parseValue
protected java.lang.Boolean parseValue(java.lang.Object obj) throws ParameterExceptionDescription copied from class:AbstractParameterParse a given value into the destination type.- Specified by:
parseValuein classAbstractParameter<Flag,java.lang.Boolean>- Parameters:
obj- Object to parse (may be a string representation!)- Returns:
- Parsed object
- Throws:
ParameterException- when the object cannot be parsed.
-
getSyntax
public java.lang.String getSyntax()
A flag has no syntax, since it doesn't take extra options- Returns:
- a string representation of the parameter's type
-
getValueAsString
public java.lang.String getValueAsString()
Description copied from interface:ParameterGet the value as string. May returnnull- Returns:
- Value as string
-
validate
protected boolean validate(java.lang.Boolean obj) throws ParameterExceptionDescription copied from class:AbstractParameterValidate a value after parsing (e.g., do constraint checks!)- Overrides:
validatein classAbstractParameter<Flag,java.lang.Boolean>- Parameters:
obj- Object to validate- Returns:
- true iff the object is valid for this parameter.
- Throws:
ParameterException- when the object is not valid.
-
setValue
public void setValue(boolean val)
Convenience function using a native boolean, that doesn't require error handling.- Parameters:
val- boolean value
-
isTrue
public boolean isTrue()
Shorthand forisDefined() && getValue() == true- Returns:
- true when defined and true.
-
isFalse
public boolean isFalse()
Shorthand forisDefined() && getValue() == false- Returns:
- true when defined and true.
-
grab
public boolean grab(Parameterization config, Flag.BooleanConsumer consumer)
Get the parameter.- Parameters:
config- Parameterizationconsumer- Output consumer- Returns:
trueif valid
-
-