net.sf.freecol.common.option
Class IntegerOption

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColObject
      extended by net.sf.freecol.common.option.AbstractOption<java.lang.Integer>
          extended by net.sf.freecol.common.option.IntegerOption
All Implemented Interfaces:
java.lang.Cloneable, Option<java.lang.Integer>
Direct Known Subclasses:
PercentageOption, SelectOption

public class IntegerOption
extends AbstractOption<java.lang.Integer>

Represents an option where the valid choice is an integer.


Field Summary
private static java.util.logging.Logger logger
           
private  int maximumValue
           
private  int minimumValue
           
private  int value
           
 
Fields inherited from class net.sf.freecol.common.option.AbstractOption
isDefined
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, INFINITY, NO_ID, PARTIAL_ATTRIBUTE, UNDEFINED, VALUE_TAG
 
Constructor Summary
IntegerOption(Specification specification)
          Creates a new IntegerOption.
IntegerOption(java.lang.String id)
          Creates a new IntegerOption.
IntegerOption(java.lang.String id, Specification specification)
          Creates a new IntegerOption.
 
Method Summary
 IntegerOption clone()
           
 int getMaximumValue()
          Returns the maximum allowed value.
 int getMinimumValue()
          Returns the minimum allowed value.
protected  java.lang.String getStringValue()
          Gets a String representation of the current value.
 java.lang.Integer getValue()
          Gets the current value of this IntegerOption.
static java.lang.String getXMLElementTagName()
          Gets the tag name of the root element representing this object.
protected  void readAttributes(javax.xml.stream.XMLStreamReader in)
          Reads the attributes of this object from an XML stream.
 void setMaximumValue(int maximumValue)
          Sets the maximum allowed value.
 void setMinimumValue(int minimumValue)
          Sets the minimum allowed value.
 void setValue(java.lang.Integer value)
          Sets the value of this IntegerOption.
protected  void setValue(java.lang.String value)
          Converts the given String to an Integer and calls setValue(Integer).
protected  void setValue(java.lang.String valueString, java.lang.String defaultValueString)
          Sets the value of this Option from the given string representation.
 java.lang.String toString()
          Returns a textual representation of this object.
protected  void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
          This method writes an XML-representation of this object to the given stream.
protected  void toXMLImpl(javax.xml.stream.XMLStreamWriter out, java.lang.String tag)
           
 
Methods inherited from class net.sf.freecol.common.option.AbstractOption
generateChoices, getGroup, isNullValueOK, readFromXMLImpl, readOption, setGroup, setValues
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getId, getPropertyChangeListeners, getPropertyChangeListeners, getSpecification, hasAbility, hasAttribute, hasListeners, readAttributes, readChild, readChild, readChildren, readChildren, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXML, readFromXMLElement, readFromXMLImpl, readFromXMLPartialImpl, removePropertyChangeListener, removePropertyChangeListener, save, save, setId, setSpecification, toXML, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, toXMLPartialImpl, writeAttribute, writeAttributes, writeChildren
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.freecol.common.option.Option
getId, readFromXML, toXML
 

Field Detail

logger

private static java.util.logging.Logger logger

value

private int value

minimumValue

private int minimumValue

maximumValue

private int maximumValue
Constructor Detail

IntegerOption

public IntegerOption(java.lang.String id)
Creates a new IntegerOption.

Parameters:
id - The identifier for this option. This is used when the object should be found in an OptionGroup.

IntegerOption

public IntegerOption(Specification specification)
Creates a new IntegerOption.

Parameters:
specification - The specification this option belongs to. May be null.

IntegerOption

public IntegerOption(java.lang.String id,
                     Specification specification)
Creates a new IntegerOption.

Parameters:
id - The identifier for this option. This is used when the object should be found in an OptionGroup.
specification - The specification this option belongs to. May be null.
Method Detail

clone

public IntegerOption clone()
Specified by:
clone in interface Option<java.lang.Integer>
Specified by:
clone in class AbstractOption<java.lang.Integer>

getMinimumValue

public int getMinimumValue()
Returns the minimum allowed value.

Returns:
The minimum value allowed by this option.

setMinimumValue

public void setMinimumValue(int minimumValue)
Sets the minimum allowed value.

Parameters:
minimumValue - The minimum value to set

getMaximumValue

public int getMaximumValue()
Returns the maximum allowed value.

Returns:
The maximum value allowed by this option.

setMaximumValue

public void setMaximumValue(int maximumValue)
Sets the maximum allowed value.

Parameters:
maximumValue - the maximum value to set

getValue

public java.lang.Integer getValue()
Gets the current value of this IntegerOption.

Specified by:
getValue in interface Option<java.lang.Integer>
Specified by:
getValue in class AbstractOption<java.lang.Integer>
Returns:
The value.

setValue

public void setValue(java.lang.Integer value)
Sets the value of this IntegerOption.

Specified by:
setValue in interface Option<java.lang.Integer>
Specified by:
setValue in class AbstractOption<java.lang.Integer>
Parameters:
value - The value to be set.

getStringValue

protected java.lang.String getStringValue()
Gets a String representation of the current value. This method can be overwritten by subclasses to allow a custom save value, since this method is used by FreeColObject.toXML(XMLStreamWriter).

Returns:
The String value of the Integer.
See Also:
setValue(String)

setValue

protected void setValue(java.lang.String value)
Converts the given String to an Integer and calls setValue(Integer).

This method can be overwritten by subclasses to allow a custom save value, since this method is used by FreeColObject.readFromXML(XMLStreamReader).

Parameters:
value - The String value of the Integer.
See Also:
getStringValue()

setValue

protected void setValue(java.lang.String valueString,
                        java.lang.String defaultValueString)
Sets the value of this Option from the given string representation. Both parameters must not be null at the same time.

Overrides:
setValue in class AbstractOption<java.lang.Integer>
Parameters:
valueString - the string representation of the value of this Option
defaultValueString - the string representation of the default value of this Option

toXMLImpl

protected void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
                  throws javax.xml.stream.XMLStreamException
This method writes an XML-representation of this object to the given stream.

Specified by:
toXMLImpl in class FreeColObject
Parameters:
out - The target stream.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.

toXMLImpl

protected void toXMLImpl(javax.xml.stream.XMLStreamWriter out,
                         java.lang.String tag)
                  throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

readAttributes

protected void readAttributes(javax.xml.stream.XMLStreamReader in)
                       throws javax.xml.stream.XMLStreamException
Reads the attributes of this object from an XML stream.

Overrides:
readAttributes in class AbstractOption<java.lang.Integer>
Parameters:
in - The XML input stream.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.

getXMLElementTagName

public static java.lang.String getXMLElementTagName()
Gets the tag name of the root element representing this object.

Returns:
"integerOption".

toString

public java.lang.String toString()
Description copied from interface: Option
Returns a textual representation of this object.

Specified by:
toString in interface Option<java.lang.Integer>
Overrides:
toString in class java.lang.Object
Returns:
The name of this Option.