edu.rice.cs.drjava.config
Class Option<T>
java.lang.Object
edu.rice.cs.drjava.config.OptionParser<T>
edu.rice.cs.drjava.config.Option<T>
- All Implemented Interfaces:
- FormatStrategy<T>, ParseStrategy<T>
- Direct Known Subclasses:
- BooleanOption, ColorOption, FileOption, FontOption, ForcedChoiceOption, IntegerOption, KeyStrokeOption, LongOption, StringOption, VectorOption
public abstract class Option<T>
- extends OptionParser<T>
- implements FormatStrategy<T>
An instance of this class represents a configurable option in DrJava that has static type T. Classes can extend
this class and the rest of the Configuration typing framework will work for it. Named subclasses aren't even
necessary -- but may be convenient in order to re-use code. For example, to make an anonymous class that handles
options of static type Integer, with the name "indent.level", you could use the following code:
Option<Integer> INDENT_LEVEL = new Option<Integer>("indent.level") {
public Integer parse(String s) {
return new Integer(s);
}
};
The precedinjg example is simple because Integers (like most data-type classes defined in the Java
libraries) have handy toString() / parsing methods/constructors.
- Version:
- $Id: Option.java 4691 2008-12-02 23:33:27Z dlsmith $
Constructor Summary |
Option(String name,
T def)
Constructor that takes in a name and default value |
Option
public Option(String name,
T def)
- Constructor that takes in a name and default value
- Parameters:
name
- the name of this option (eg. "indent.level");def
- the default value for this option (eg. "2")
format
public String format(T value)
- Formats a statically typed T value as a String. The default implementation uses the toString() method.
- Specified by:
format
in interface FormatStrategy<T>
- Parameters:
value
- the statically-typed value to format into a String
- Throws:
NullPointerException
- if value is null
getDefaultString
public String getDefaultString()
- Specified by:
getDefaultString
in class OptionParser<T>
- Returns:
- the default value as a string