Package net.sf.freecol.common.option
Class ListOption<T>
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColSpecObject
-
- net.sf.freecol.common.option.AbstractOption<java.util.List<AbstractOption<T>>>
-
- net.sf.freecol.common.option.ListOption<T>
-
- All Implemented Interfaces:
java.lang.Cloneable
,java.lang.Comparable<FreeColObject>
,ObjectWithId
,Option<java.util.List<AbstractOption<T>>>
- Direct Known Subclasses:
ModListOption
,UnitListOption
public abstract class ListOption<T> extends AbstractOption<java.util.List<AbstractOption<T>>>
Represents a list of Options.
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
allowDuplicates
Whether the list can include duplicates.private static java.util.logging.Logger
logger
private static java.lang.String
MAXIMUM_NUMBER_TAG
private int
maximumNumber
The maximum number of list entries.private AbstractOption<T>
template
The AbstractOption used to generate new values.private static java.lang.String
TEMPLATE_TAG
private java.util.List<AbstractOption<T>>
value
The list of options.-
Fields inherited from class net.sf.freecol.common.option.AbstractOption
ACTION_TAG, DEFAULT_VALUE_TAG, isDefined
-
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE_TAG, DEFAULT_CLASS_INDEX, fcoComparator, ID_ATTRIBUTE_TAG, PARTIAL_ATTRIBUTE_TAG, VALUE_TAG
-
-
Constructor Summary
Constructors Constructor Description ListOption(java.lang.String id, Specification specification)
Creates a newListOption
.ListOption(Specification specification)
Creates a newListOption
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addMember(AbstractOption<T> ao)
Add a member to the values list.boolean
canAdd(AbstractOption<T> ao)
Can an option be added to this list?boolean
getAllowDuplicates()
Does this list allow duplicates?int
getMaximumNumber()
Gets the maximum number of allowed values.java.util.List<T>
getOptionValues()
Get the values of the current non-null options in the list.AbstractOption<T>
getTemplate()
Gets the generating template.java.util.List<AbstractOption<T>>
getValue()
Gets the current value of thisListOption
.boolean
isNullValueOK()
Is null an acceptable value for this option? Override this in subclasses where necessary.void
readAttributes(FreeColXMLReader xr)
Reads the attributes of this object from an XML stream.void
readChild(FreeColXMLReader xr)
Reads a single child object.private AbstractOption<T>
readChildOption(FreeColXMLReader xr)
Hack to suppress warning when reading a typed option.void
readChildren(FreeColXMLReader xr)
Reads the children of this object from an XML stream.void
setAllowDuplicates(boolean allowDuplicates)
Set the deduplicatation flag.protected void
setListValues(ListOption<T> lo)
Set the list option values from another list option.void
setMaximumNumber(int maximumNumber)
Sets the maximum number of allowed values.void
setTemplate(AbstractOption<T> template)
Sets the generating template.void
setValue(java.util.List<AbstractOption<T>> value)
Sets the value of thisListOption
.java.lang.String
toString()
protected void
writeAttributes(FreeColXMLWriter xw)
Write the attributes of this object to a stream.protected void
writeChildren(FreeColXMLWriter xw)
Write the children of this object to a stream.-
Methods inherited from class net.sf.freecol.common.option.AbstractOption
cloneOption, generateChoices, getEnabledBy, getGroup, readOption, setGroup, setValue, setValues
-
Methods inherited from class net.sf.freecol.common.model.FreeColSpecObject
copyIn, getSpecification, setSpecification
-
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addAbility, addFeatures, addModifier, addPropertyChangeListener, addPropertyChangeListener, apply, apply, applyModifiers, applyModifiers, arrayKey, compareIds, compareTo, containsAbilityKey, containsModifierKey, copy, copy, copy, copy, copyInCast, dumpObject, equals, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAbilities, getAbilities, getAbilities, getAbilities, getClassIndex, getDefenceModifiers, getDisplayObject, getFeatureContainer, getFreeColObjectClass, getFreeColObjectClassByName, getGame, getId, getIdNumber, getIdType, getIdTypeByName, getModifiers, getModifiers, getModifiers, getModifiers, getObjectClassIndex, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getSortedAbilities, getSortedModifiers, getSuffix, getSuffix, getXMLTagName, hasAbility, hasAbility, hasAbility, hashCode, hasListeners, hasModifier, hasModifier, hasModifier, idEquals, invokeMethod, logFreeColObjects, readFromXML, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setGame, setId, toXML, toXML, toXMLPartial, toXMLPartial
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sf.freecol.common.ObjectWithId
getId
-
Methods inherited from interface net.sf.freecol.common.option.Option
readFromXML, toXML
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
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.
-
value
private final java.util.List<AbstractOption<T>> value
The list of options.
-
allowDuplicates
protected boolean allowDuplicates
Whether the list can include duplicates. This was always true before adding this variable so the default should remain == true.
-
MAXIMUM_NUMBER_TAG
private static final java.lang.String MAXIMUM_NUMBER_TAG
- See Also:
- Constant Field Values
-
TEMPLATE_TAG
private static final java.lang.String TEMPLATE_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ListOption
public ListOption(Specification specification)
Creates a newListOption
.- Parameters:
specification
- TheSpecification
to refer to.
-
ListOption
public ListOption(java.lang.String id, Specification specification)
Creates a newListOption
.- Parameters:
id
- The object identifier.specification
- TheSpecification
to refer to.
-
-
Method Detail
-
getTemplate
public AbstractOption<T> getTemplate()
Gets the generating template.- Returns:
- The template.
-
setTemplate
public void setTemplate(AbstractOption<T> template)
Sets the generating template.- Parameters:
template
- The template to set.
-
getMaximumNumber
public int getMaximumNumber()
Gets the maximum number of allowed values.- Returns:
- The maximum number of allowed values for this option.
-
setMaximumNumber
public void setMaximumNumber(int maximumNumber)
Sets the maximum number of allowed values.- Parameters:
maximumNumber
- The new maximum number of allowed values.
-
getOptionValues
public java.util.List<T> getOptionValues()
Get the values of the current non-null options in the list.- Returns:
- A list of option values.
-
addMember
private void addMember(AbstractOption<T> ao)
Add a member to the values list.- Parameters:
ao
- The newAbstractOption
member to add.
-
getAllowDuplicates
public boolean getAllowDuplicates()
Does this list allow duplicates?- Returns:
- True if duplicates are allowed.
-
setAllowDuplicates
public void setAllowDuplicates(boolean allowDuplicates)
Set the deduplicatation flag.- Parameters:
allowDuplicates
- The new deduplication flag;
-
canAdd
public boolean canAdd(AbstractOption<T> ao)
Can an option be added to this list?- Parameters:
ao
- The option to check.- Returns:
- True if the option can be added.
-
setListValues
protected void setListValues(ListOption<T> lo)
Set the list option values from another list option.- Parameters:
lo
- The otherListOption
.
-
getValue
public java.util.List<AbstractOption<T>> getValue()
Gets the current value of thisListOption
.- Specified by:
getValue
in interfaceOption<T>
- Specified by:
getValue
in classAbstractOption<java.util.List<AbstractOption<T>>>
- Returns:
- The value.
-
setValue
public void setValue(java.util.List<AbstractOption<T>> value)
Sets the value of thisListOption
.- Specified by:
setValue
in interfaceOption<T>
- Specified by:
setValue
in classAbstractOption<java.util.List<AbstractOption<T>>>
- Parameters:
value
- The value to be set.
-
isNullValueOK
public boolean isNullValueOK()
Is null an acceptable value for this option? Override this in subclasses where necessary.- Overrides:
isNullValueOK
in classAbstractOption<java.util.List<AbstractOption<T>>>
- Returns:
- False.
-
writeAttributes
protected void writeAttributes(FreeColXMLWriter xw) throws javax.xml.stream.XMLStreamException
Write the attributes of this object to a stream. To be overridden if required by any object that has attributes and uses the toXML(FreeColXMLWriter, String) call.- Overrides:
writeAttributes
in classAbstractOption<java.util.List<AbstractOption<T>>>
- Parameters:
xw
- TheFreeColXMLWriter
to write to.- Throws:
javax.xml.stream.XMLStreamException
- if there are any problems writing to the stream.
-
writeChildren
protected void writeChildren(FreeColXMLWriter xw) throws javax.xml.stream.XMLStreamException
Write the children of this object to a stream. To be overridden if required by any object that has children and uses the toXML(FreeColXMLWriter, String) call.- Overrides:
writeChildren
in classFreeColObject
- Parameters:
xw
- TheFreeColXMLWriter
to write to.- Throws:
javax.xml.stream.XMLStreamException
- if there are any problems writing to the stream.
-
readAttributes
public void readAttributes(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the attributes of this object from an XML stream.- Overrides:
readAttributes
in classAbstractOption<java.util.List<AbstractOption<T>>>
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
readChildren
public void readChildren(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the children of this object from an XML stream.- Overrides:
readChildren
in classFreeColObject
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
readChild
public void readChild(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads a single child object. Subclasses must override to read their enclosed elements. This particular instance of the routine always throws XMLStreamException because we should never arrive here. However it is very useful to always call super.readChild() when an unexpected tag is encountered, as the exception thrown here provides some useful debugging context.- Overrides:
readChild
in classFreeColObject
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
readChildOption
private AbstractOption<T> readChildOption(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Hack to suppress warning when reading a typed option. FIXME: Work out how to make this go away.- Parameters:
xr
- TheFreeColXMLReader
to read from.- Returns:
- A child typed
AbstractOption
. - Throws:
javax.xml.stream.XMLStreamException
- if the stream is corrupt.
-
toString
public java.lang.String toString()
- Specified by:
toString
in interfaceOption<T>
- Overrides:
toString
in classFreeColObject
-
-