Class BooleanOption

  • All Implemented Interfaces:
    OptionModifiable

    public class BooleanOption
    extends Option
    This class is used for options with boolean values. There are several ways to invoke a boolean option at the command line.

    For example, a plus (true) or minus (false) sign directly after the short or long option may be used.

      myprogram -a+ -b- --longa+ --longb-
     
    The following keywords may be used to invoke an option using the assignment form.
    • +
    • -
    • true
    • false
    • yes
    • no
    • on
    • off
    • activated
    • not activated
    • active
    • inactive

    To invoke an option using assignment form where <value> is the <value> of the option, use the following syntax.

      myprogram -a=<keyword> -b <keyword> --longa=<keyword> --longb=<keyword>
     
    Invoking a boolean option without using any of the aforementioned keywords and forms will set the option to true by default.
     Copyright (C) Damian Ryan Eads, 2001. All Rights Reserved.
    
     ritopt is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
    
     ritopt is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
    
     You should have received a copy of the GNU General Public License
     along with ritopt; if not, write to the Free Software
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     
    • Constructor Detail

      • BooleanOption

        public BooleanOption()
        Constructs a boolean option that is initially false.
      • BooleanOption

        public BooleanOption​(BooleanOption op)
        Constructs a boolean option by copying the boolean option passed.
        Parameters:
        op - The boolean option to copy.
      • BooleanOption

        public BooleanOption​(boolean value)
        Constructs a boolean option initialized with the value passed.
        Parameters:
        value - The initial value of this boolean option.
      • BooleanOption

        public BooleanOption​(boolean value,
                             java.lang.String longOption)
        Constructs a boolean option initialized with the value and long option passed.
        Parameters:
        value - The initial value of this boolean option.
        longOption - The long option associated with this option.
      • BooleanOption

        public BooleanOption​(boolean value,
                             char shortOption)
        Constructs a boolean option initialized with the value and short option passed.
        Parameters:
        value - The initial value of this boolean option.
        shortOption - The short option associated with this option.
      • BooleanOption

        public BooleanOption​(boolean value,
                             java.lang.String longOption,
                             char shortOption)
        Constructs a boolean option initialized with the value, short and long option passed.
        Parameters:
        shortOption - The short option associated with this option.
        longOption - The long option associated with this option.
        value - The initial value of this boolean option.
    • Method Detail

      • getObject

        public java.lang.Object getObject()
        Return the value as an object.
        Specified by:
        getObject in class Option
        Returns:
        This value as an option.
      • modify

        public void modify​(java.lang.String value)
                    throws OptionModificationException
        Modify this option based on a string representation. Acceptable values are +, -, true, false, yes, no, on, off, activated, not activated, active, and inactive.
        Parameters:
        value - String representation of the object.
        Throws:
        OptionModificationException - Thrown if an error occurs during modification of an option.
      • setValue

        public void setValue​(java.lang.String value)
                      throws OptionModificationException
        Modify this option based on a string representation. Acceptable values are +, -, true, false, yes, no, on, off, activated, not activated, active, inactive.
        Parameters:
        value - String representation of the object.
        Throws:
        OptionModificationException - Thrown if an error occurs during modification of an option.
      • setValue

        public void setValue​(boolean value)
        Modify this option using a boolean value.
        Parameters:
        value - A boolean value.
      • getValue

        public boolean getValue()
        Return this option as a boolean.
        Returns:
        This option as a boolean.
      • getStringValue

        public java.lang.String getStringValue()
        Return this option as a string.
        Specified by:
        getStringValue in class Option
        Returns:
        This option as a string.
      • getTypeName

        public java.lang.String getTypeName()
        Returns the type name of this option. For a BooleanOption, "BOOLEAN" is returned.
        Specified by:
        getTypeName in class Option
        Returns:
        The type name of this option.
      • toString

        public java.lang.String toString()
        Returns a string representation of this object.
        Overrides:
        toString in class java.lang.Object
        Returns:
        A string representation of this object.