edu.rice.cs.drjava.config
Class ForcedChoiceOption

java.lang.Object
  extended by edu.rice.cs.drjava.config.OptionParser<T>
      extended by edu.rice.cs.drjava.config.Option<String>
          extended by edu.rice.cs.drjava.config.ForcedChoiceOption
All Implemented Interfaces:
FormatStrategy<String>, ParseStrategy<String>

public class ForcedChoiceOption
extends Option<String>

Class defining a configuration option that requires a choice between mutually-exclusive possible values. Values are stored as Strings, though this could be extended to any type with a fairly simple refactoring.

Version:
$Id: ForcedChoiceOption.java 4447 2008-04-18 16:06:34Z rcartwright $

Field Summary
 
Fields inherited from class edu.rice.cs.drjava.config.OptionParser
defaultValue, name
 
Constructor Summary
ForcedChoiceOption(String key, String def, Collection<String> choices)
           
 
Method Summary
 String format(String s)
          Formats a statically typed T value as a String.
 Iterator<String> getLegalValues()
          Gets all legal values of this option.
 int getNumValues()
          Gets the number of legal values for this option.
 boolean isLegal(String s)
          Checks whether the parameter String is a legal value for this option.
 String parse(String s)
          Parses an arbitrary String into an acceptable value for this option.
 
Methods inherited from class edu.rice.cs.drjava.config.Option
getDefaultString
 
Methods inherited from class edu.rice.cs.drjava.config.OptionParser
getDefault, getName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ForcedChoiceOption

public ForcedChoiceOption(String key,
                          String def,
                          Collection<String> choices)
Parameters:
key - The name of this option.
def - The default value of the option.
choices - A collection of all possible values of this Option, as Strings.
Method Detail

isLegal

public boolean isLegal(String s)
Checks whether the parameter String is a legal value for this option. The input String must be formatted exactly like the original, as defined by String.equals(String).

Parameters:
s - the value to check
Returns:
true if s is legal, false otherwise

getLegalValues

public Iterator<String> getLegalValues()
Gets all legal values of this option.

Returns:
an Iterator containing the set of all Strings for which isLegal returns true.

getNumValues

public int getNumValues()
Gets the number of legal values for this option.

Returns:
an int indicating the number of legal values.

parse

public String parse(String s)
Parses an arbitrary String into an acceptable value for this option.

Specified by:
parse in interface ParseStrategy<String>
Specified by:
parse in class OptionParser<String>
Parameters:
s - The String to be parsed.
Returns:
s, if s is a legal value of this option.
Throws:
IllegalArgumentException - if "s" is not one of the allowed values.

format

public String format(String s)
Description copied from class: Option
Formats a statically typed T value as a String. The default implementation uses the toString() method.

Specified by:
format in interface FormatStrategy<String>
Overrides:
format in class Option<String>
Parameters:
s - The String to be formatted.
Returns:
"s", no actual formatting is performed.