Class 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
    • 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 ParameterException
        Description copied from class: AbstractParameter
        Parse a given value into the destination type.
        Specified by:
        parseValue in class AbstractParameter<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: Parameter
        Get the value as string. May return null
        Returns:
        Value as string
      • validate

        protected boolean validate​(java.lang.Boolean obj)
                            throws ParameterException
        Description copied from class: AbstractParameter
        Validate a value after parsing (e.g., do constraint checks!)
        Overrides:
        validate in class AbstractParameter<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 for isDefined() && getValue() == true
        Returns:
        true when defined and true.
      • isFalse

        public boolean isFalse()
        Shorthand for isDefined() && getValue() == false
        Returns:
        true when defined and true.
      • grab

        public boolean grab​(Parameterization config,
                            Flag.BooleanConsumer consumer)
        Get the parameter.
        Parameters:
        config - Parameterization
        consumer - Output consumer
        Returns:
        true if valid