org.vmutil.options
Class EnumOption

java.lang.Object
  extended by org.vmutil.options.Option
      extended by org.vmutil.options.EnumOption
Direct Known Subclasses:
DummyEnum, NurseryZeroing

public class EnumOption
extends Option

An option that is a selection of several strings. The mapping between strings and integers is determined using indexes into a string array.

Enumerations are case sensitive.


Field Summary
protected  int defaultValue
           
protected  int value
           
protected  String[] values
           
 
Fields inherited from class org.vmutil.options.Option
ADDRESS_OPTION, BOOLEAN_OPTION, ENUM_OPTION, FLOAT_OPTION, INT_OPTION, MICROSECONDS_OPTION, PAGES_OPTION, RAW, READABLE, set, STRING_OPTION, XML
 
Constructor Summary
protected EnumOption(OptionSet set, String name, String description, String[] values, String defaultValue)
          Create a new enumeration option.
 
Method Summary
private  int findValue(String string)
          Search for a string in the enumeration.
 int getDefaultValue()
          Read the default value of the option.
 String getDefaultValueString()
          Read the string for the default value of the option.
 int getValue()
          Read the current value of the option.
 String[] getValues()
          Return the array of allowed enumeration values.
 String getValueString()
          Read the string for the current value of the option.
 void setDefaultValue(String value)
          Modify the default value of the option.
 void setValue(int value)
          Update the value of the option, echoing the change if the echoOptions option is set.
 void setValue(String value)
          Look up the value for a string and update the value of the option accordingly, echoing the change if the echoOptions option is set.
 
Methods inherited from class org.vmutil.options.Option
fail, failIf, getDescription, getKey, getName, getNext, getType, setNext, validate, warn, warnIf
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultValue

protected int defaultValue

value

protected int value

values

protected String[] values
Constructor Detail

EnumOption

protected EnumOption(OptionSet set,
                     String name,
                     String description,
                     String[] values,
                     String defaultValue)
Create a new enumeration option.

Parameters:
set - The option set this option belongs to.
name - The space separated name for the option.
description - The purpose of the option.
values - A mapping of int to string for the enum.
defaultValue - The default value of the option.
Method Detail

findValue

private int findValue(String string)
Search for a string in the enumeration.

Returns:
The index of the passed string.

getValue

public int getValue()
Read the current value of the option.

Returns:
The option value.

getValueString

public String getValueString()
Read the string for the current value of the option.

Returns:
The option value.

getDefaultValue

public int getDefaultValue()
Read the default value of the option.

Returns:
The default value.

getDefaultValueString

public String getDefaultValueString()
Read the string for the default value of the option.

Returns:
The default value.

setValue

public void setValue(int value)
Update the value of the option, echoing the change if the echoOptions option is set. This method also calls the validate method to allow subclasses to perform any required validation.

Parameters:
value - The new value for the option.

setValue

public void setValue(String value)
Look up the value for a string and update the value of the option accordingly, echoing the change if the echoOptions option is set. This method also calls the validate method to allow subclasses to perform any required validation.

Parameters:
value - The new value for the option.

setDefaultValue

public void setDefaultValue(String value)
Modify the default value of the option.

Parameters:
value - The new default value for the option.

getValues

public String[] getValues()
Return the array of allowed enumeration values.

Returns:
The values array.