Class Option


  • public class Option
    extends java.lang.Object
    Container class to hold a name, value, and class of the value.
    • Constructor Summary

      Constructors 
      Constructor Description
      Option​(java.lang.String name, java.lang.Class<?> valueClass)
      Construct a new Option.
      Option​(java.lang.String name, java.lang.Class<?> valueClass, java.lang.Object value, java.lang.String arg, java.lang.String group)
      Construct a new Option
      Option​(java.lang.String name, java.lang.Object value)
      Construct a new Option.
      Option​(java.lang.String name, java.lang.Object value, java.lang.Class<?> valueClass, java.lang.String arg)
      Construct a new Option
      Option​(java.lang.String group, java.lang.String name, java.lang.Object value)
      Construct a new Option.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Option copy()
      Creates a copy of this Option object.
      java.lang.String getArg()
      Return the command line argument for this Option.
      java.awt.Component getCustomEditorComponent()
      Override if you want to provide a custom widget for selecting your options.
      java.lang.String getGroup()
      Return the group name for this option; may be null if group was not specified.
      java.lang.String getName()
      Return the name of this Option.
      java.lang.Object getValue()
      Return the value of this Option.
      java.lang.Class<?> getValueClass()
      Return the class of the value for this Option.
      boolean parseAndSetValueByType​(java.lang.String str, AddressFactory addressFactory)
      Set the value for this option by parsing the given string and converting it to the option's type.
      void setOptionListener​(OptionListener listener)  
      void setValue​(java.lang.Object object)
      Set the value for this option.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Option

        public Option​(java.lang.String name,
                      java.lang.Object value)
        Construct a new Option.
        Parameters:
        name - name of the option
        value - value of the option. Value can't be null with this constructor.
        Throws:
        java.lang.IllegalArgumentException - if value is null
      • Option

        public Option​(java.lang.String group,
                      java.lang.String name,
                      java.lang.Object value)
        Construct a new Option.
        Parameters:
        group - Name for group of options
        name - name of the option
        value - value of the option
        Throws:
        java.lang.IllegalArgumentException - if value is null
      • Option

        public Option​(java.lang.String name,
                      java.lang.Class<?> valueClass)
        Construct a new Option.
        Parameters:
        name - name of the option
        valueClass - class of the option's value
      • Option

        public Option​(java.lang.String name,
                      java.lang.Object value,
                      java.lang.Class<?> valueClass,
                      java.lang.String arg)
        Construct a new Option
        Parameters:
        name - name of the option
        value - value of the option
        valueClass - class of the option's value
        arg - the option's command line argument
      • Option

        public Option​(java.lang.String name,
                      java.lang.Class<?> valueClass,
                      java.lang.Object value,
                      java.lang.String arg,
                      java.lang.String group)
        Construct a new Option
        Parameters:
        name - name of the option
        valueClass - class of the option's value
        value - value of the option
        arg - the option's command line argument
        group - Name for group of options
    • Method Detail

      • setOptionListener

        public void setOptionListener​(OptionListener listener)
      • getCustomEditorComponent

        public java.awt.Component getCustomEditorComponent()
        Override if you want to provide a custom widget for selecting your options.

        Important! If you override this you MUST also override the copy() method so it returns a new instance of your custom editor.

        Returns:
        the custom editor
      • getValueClass

        public java.lang.Class<?> getValueClass()
        Return the class of the value for this Option.
      • getGroup

        public java.lang.String getGroup()
        Return the group name for this option; may be null if group was not specified.
      • getName

        public java.lang.String getName()
        Return the name of this Option.
      • getValue

        public java.lang.Object getValue()
        Return the value of this Option.
      • setValue

        public void setValue​(java.lang.Object object)
        Set the value for this option.
        Parameters:
        object - value of this option
      • parseAndSetValueByType

        public boolean parseAndSetValueByType​(java.lang.String str,
                                              AddressFactory addressFactory)
        Set the value for this option by parsing the given string and converting it to the option's type. Fails if this option doesn't have a type associated with it, or if an unsupported type is needed to be parsed.
        Parameters:
        str - The value to set, in string form.
        addressFactory - An address factory to use for when the option trying to be set is an Address. If null, an exception will be thrown for Address type options.
        Returns:
        True if the value was successfully parsed and set; otherwise, false.
      • getArg

        public java.lang.String getArg()
        Return the command line argument for this Option.
        Returns:
        The command line argument for this Option. Could be null.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • copy

        public Option copy()
        Creates a copy of this Option object.
        Returns:
        a copy of this Option object.