cdx.scorebot.util.config
Class ConfigOption<T>

java.lang.Object
  extended by cdx.scorebot.util.config.ConfigOption<T>
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
ConfigBoolean, ConfigDouble, ConfigInteger, ConfigString

public abstract class ConfigOption<T>
extends java.lang.Object
implements java.io.Serializable

Declares translation methods a parameter must have so it can be translated between a form representable on the Configurer GUI and a form useful to the Test itself. This allows new parameter types to be added without changing how the GUI works or what it needs to do to get parameter values for the Test. This also allows for the type of component in the GUI and a selection of valid values to be specified.

Author:
David Underhill
See Also:
Serialized Form

Field Summary
protected  java.util.Vector<T> possValues
          the valid values for the option (this is empty if the ComponType is either ANY or BINARY).
 
Constructor Summary
ConfigOption(T option)
          Instantiates a ConfigOption with no restricted values (unless the option is a Boolean, in which case the ComponType is BINARY else ANY).
ConfigOption(T option, T[] possValues)
          Instantiates a ConfigOption with specified allowed values.
 
Method Summary
 void addValue(T t)
          Adds a value which this variable can take on.
 boolean equals(ConfigOption o)
           
abstract  java.util.Vector<T> getAllowedValuesCopy()
          gets a COPY of the possible values this component may take on (these values are only used if ComponType is MULTI or BINARY).
 ComponType getComponType()
          gets the kind of support a component the GUI should use to display the option
 T getCurrentValue()
          gets the currently selected option's value
 int getCurrentValueIndex()
          gets the currently selected option's index in the values vector
 java.lang.String getName()
          gets the name of the option, if set
abstract  ConfigOption getShortCopy()
          Returns a copy of this configuration option.
 java.lang.String getType()
          gets the name of the type that this ConfigOption holds (class name only - no package qualification)
 T getValue(int index)
          Gets the specified value which this variable can take on.
 java.util.Vector<T> getValues()
          gets the values this variable may be
 VariableType getVarianceType()
          gets how this option varies in value
 void nextValue()
          Chooses the "next" value as specified by the VariableType varianceType
 void removeValue(int index)
          Removes the value from the values this ConfigVariableOption can take on
 void setCurrentValue(T option)
          sets the currently selected value to this new value
 void setName(java.lang.String name)
          sets the name of the option
 void setVarianceType(VariableType type)
          sets how this option varies in value
 java.lang.String toString()
          returns the name of the config option
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

possValues

protected final java.util.Vector<T> possValues
the valid values for the option (this is empty if the ComponType is either ANY or BINARY). This field should NOT be modified by any overriding classes.

Constructor Detail

ConfigOption

public ConfigOption(T option)
Instantiates a ConfigOption with no restricted values (unless the option is a Boolean, in which case the ComponType is BINARY else ANY).

Parameters:
option - initial value of the option

ConfigOption

public ConfigOption(T option,
                    T[] possValues)
Instantiates a ConfigOption with specified allowed values. The ComponType will be BINARY if the option is a Boolean, MULTI if possValues is not null, and ANY otherwise. If the ComponType is MULTI, possValues is coerced so that it contains option as one of the possible values (if it doesn't already contain it as a possible value).

Parameters:
option - initial value of the option
possValues - what kind of values a component will need to work with for this option
Method Detail

equals

public boolean equals(ConfigOption o)

getAllowedValuesCopy

public abstract java.util.Vector<T> getAllowedValuesCopy()
gets a COPY of the possible values this component may take on (these values are only used if ComponType is MULTI or BINARY).

Returns:
COPY of the possible values the component may take on if it is of type MULTI

getShortCopy

public abstract ConfigOption getShortCopy()
Returns a copy of this configuration option. The copy will only contain the current value as returned by getOption. None of the "allowed values" other than the currently selected value will be included in this copy. A reference to the current possible values will be included since they are read-only.

Returns:
a deep copy of this ConfigOption which only contains the current value

nextValue

public void nextValue()
Chooses the "next" value as specified by the VariableType varianceType


getVarianceType

public VariableType getVarianceType()
gets how this option varies in value


setVarianceType

public void setVarianceType(VariableType type)
sets how this option varies in value


getComponType

public ComponType getComponType()
gets the kind of support a component the GUI should use to display the option


getType

public final java.lang.String getType()
gets the name of the type that this ConfigOption holds (class name only - no package qualification)


getCurrentValue

public T getCurrentValue()
gets the currently selected option's value


setCurrentValue

public void setCurrentValue(T option)
sets the currently selected value to this new value


addValue

public void addValue(T t)
Adds a value which this variable can take on.

Parameters:
t - the value to add to this ConfigVariableOption's values

getCurrentValueIndex

public int getCurrentValueIndex()
gets the currently selected option's index in the values vector


getValue

public T getValue(int index)
           throws java.lang.ArrayIndexOutOfBoundsException
Gets the specified value which this variable can take on.

Parameters:
index - remove the value at the specified index.
Returns:
the value at the specified index.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.

getValues

public java.util.Vector<T> getValues()
gets the values this variable may be


removeValue

public void removeValue(int index)
                 throws java.lang.ArrayIndexOutOfBoundsException
Removes the value from the values this ConfigVariableOption can take on

Parameters:
index - remove the value at the specified index.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.

getName

public java.lang.String getName()
gets the name of the option, if set


setName

public void setName(java.lang.String name)
sets the name of the option


toString

public java.lang.String toString()
returns the name of the config option

Overrides:
toString in class java.lang.Object