net.sf.freecol.common.option
Class ListOption<T>

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColObject
      extended by net.sf.freecol.common.option.AbstractOption<java.util.List<AbstractOption<T>>>
          extended by net.sf.freecol.common.option.ListOption<T>
All Implemented Interfaces:
java.lang.Cloneable, Option<java.util.List<AbstractOption<T>>>
Direct Known Subclasses:
ModListOption, UnitListOption

public class ListOption<T>
extends AbstractOption<java.util.List<AbstractOption<T>>>

Represents a List of Options.


Field Summary
private static java.util.logging.Logger logger
           
private  int maximumNumber
          The maximum number of list entries.
private  AbstractOption<T> template
          The AbstractOption used to generate new values.
private  java.util.List<AbstractOption<T>> value
          A list of Options.
 
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
ListOption(Specification specification)
          Creates a new ListOption.
ListOption(java.lang.String id)
          Creates a new ListOption.
 
Method Summary
 ListOption<T> clone()
           
 int getMaximumValue()
          Returns the maximum allowed value.
 java.util.List<T> getOptionValues()
           
 AbstractOption<T> getTemplate()
           
 java.util.List<AbstractOption<T>> getValue()
          Gets the current value of this ListOption.
static java.lang.String getXMLElementTagName()
          Gets the tag name of the root element representing this object.
 boolean isNullValueOK()
          Returns whether null is an acceptable value for this AbstractOption.
protected  void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
          Initialize this object from an XML-representation of this object.
 void setMaximumValue(int maximumNumber)
          Sets the maximum allowed value.
 void setTemplate(AbstractOption<T> template)
           
 void setValue(java.util.List<AbstractOption<T>> value)
          Sets the value of this ListOption.
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, readAttributes, readOption, setGroup, setValue, 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, toString, wait, wait, wait
 
Methods inherited from interface net.sf.freecol.common.option.Option
getId, readFromXML, toString, toXML
 

Field Detail

logger

private static java.util.logging.Logger logger

value

private java.util.List<AbstractOption<T>> value
A list of Options.


template

private AbstractOption<T> template
The AbstractOption used to generate new values.


maximumNumber

private int maximumNumber
The maximum number of list entries. Defaults to Integer.MAX_VALUE.

Constructor Detail

ListOption

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

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

ListOption

public ListOption(Specification specification)
Creates a new ListOption.

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

clone

public ListOption<T> clone()
Specified by:
clone in interface Option<java.util.List<AbstractOption<T>>>
Specified by:
clone in class AbstractOption<java.util.List<AbstractOption<T>>>

getMaximumValue

public int getMaximumValue()
Returns the maximum allowed value.

Returns:
The maximum value allowed by this option.

setMaximumValue

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

Parameters:
maximumNumber - the maximum value to set

getValue

public java.util.List<AbstractOption<T>> getValue()
Gets the current value of this ListOption.

Specified by:
getValue in interface Option<java.util.List<AbstractOption<T>>>
Specified by:
getValue in class AbstractOption<java.util.List<AbstractOption<T>>>
Returns:
The value.

getOptionValues

public java.util.List<T> getOptionValues()

setValue

public void setValue(java.util.List<AbstractOption<T>> value)
Sets the value of this ListOption.

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

getTemplate

public AbstractOption<T> getTemplate()

setTemplate

public void setTemplate(AbstractOption<T> template)

isNullValueOK

public boolean isNullValueOK()
Returns whether null is an acceptable value for this AbstractOption. This method always returns true.

Overrides:
isNullValueOK in class AbstractOption<java.util.List<AbstractOption<T>>>
Returns:
true

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

readFromXMLImpl

protected void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
                        throws javax.xml.stream.XMLStreamException
Initialize this object from an XML-representation of this object.

Overrides:
readFromXMLImpl in class AbstractOption<java.util.List<AbstractOption<T>>>
Parameters:
in - The input stream with the XML.
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:
"unitListOption".