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 booleanallowDuplicatesWhether the list can include duplicates.private static java.util.logging.Loggerloggerprivate static java.lang.StringMAXIMUM_NUMBER_TAGprivate intmaximumNumberThe maximum number of list entries.private AbstractOption<T>templateThe AbstractOption used to generate new values.private static java.lang.StringTEMPLATE_TAGprivate java.util.List<AbstractOption<T>>valueThe 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 voidaddMember(AbstractOption<T> ao)Add a member to the values list.booleancanAdd(AbstractOption<T> ao)Can an option be added to this list?booleangetAllowDuplicates()Does this list allow duplicates?intgetMaximumNumber()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.booleanisNullValueOK()Is null an acceptable value for this option? Override this in subclasses where necessary.voidreadAttributes(FreeColXMLReader xr)Reads the attributes of this object from an XML stream.voidreadChild(FreeColXMLReader xr)Reads a single child object.private AbstractOption<T>readChildOption(FreeColXMLReader xr)Hack to suppress warning when reading a typed option.voidreadChildren(FreeColXMLReader xr)Reads the children of this object from an XML stream.voidsetAllowDuplicates(boolean allowDuplicates)Set the deduplicatation flag.protected voidsetListValues(ListOption<T> lo)Set the list option values from another list option.voidsetMaximumNumber(int maximumNumber)Sets the maximum number of allowed values.voidsetTemplate(AbstractOption<T> template)Sets the generating template.voidsetValue(java.util.List<AbstractOption<T>> value)Sets the value of thisListOption.java.lang.StringtoString()protected voidwriteAttributes(FreeColXMLWriter xw)Write the attributes of this object to a stream.protected voidwriteChildren(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- TheSpecificationto refer to.
-
ListOption
public ListOption(java.lang.String id, Specification specification)Creates a newListOption.- Parameters:
id- The object identifier.specification- TheSpecificationto 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 newAbstractOptionmember 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:
getValuein interfaceOption<T>- Specified by:
getValuein 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:
setValuein interfaceOption<T>- Specified by:
setValuein 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:
isNullValueOKin 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:
writeAttributesin classAbstractOption<java.util.List<AbstractOption<T>>>- Parameters:
xw- TheFreeColXMLWriterto 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:
writeChildrenin classFreeColObject- Parameters:
xw- TheFreeColXMLWriterto 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:
readAttributesin classAbstractOption<java.util.List<AbstractOption<T>>>- Parameters:
xr- TheFreeColXMLReaderto 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:
readChildrenin classFreeColObject- Parameters:
xr- TheFreeColXMLReaderto 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:
readChildin classFreeColObject- Parameters:
xr- TheFreeColXMLReaderto 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- TheFreeColXMLReaderto 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:
toStringin interfaceOption<T>- Overrides:
toStringin classFreeColObject
-
-