Package net.sf.freecol.common.option
Class UnitTypeOption
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColSpecObject
-
- net.sf.freecol.common.option.AbstractOption<UnitType>
-
- net.sf.freecol.common.option.UnitTypeOption
-
- All Implemented Interfaces:
java.lang.Cloneable
,java.lang.Comparable<FreeColObject>
,ObjectWithId
,Option<UnitType>
public class UnitTypeOption extends AbstractOption<UnitType>
Option wrapping a UnitType.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
UnitTypeOption.TypeSelector
FIXME: replace with Predicates.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
ADD_NONE_TAG
private boolean
addNone
Whether to add "none" to the list of choices to be generated.private static java.lang.String
CHOICE_TAG
private java.util.List<UnitType>
choices
A list of choices to provide to the UI.private static java.lang.String
GENERATE_TAG
private static java.util.logging.Logger
logger
private UnitTypeOption.TypeSelector
selector
Which choices to generate.static java.lang.String
TAG
private UnitType
value
The option value.-
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 UnitTypeOption(java.lang.String id, Specification specification)
Creates a newUnitTypeOption
.UnitTypeOption(Specification specification)
Creates a newUnitTypeOption
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addNone()
Is "none" a valid choice for this option?UnitTypeOption
cloneOption()
Clone this option.void
generateChoices()
Generate the choices to provide to the UI.java.util.List<UnitType>
getChoices()
Get the list of choices for this option.UnitTypeOption.TypeSelector
getSelector()
Get the type of choices to generate.UnitType
getValue()
Gets the current value of thisUnitTypeOption
.java.lang.String
getXMLTagName()
Get the serialization tag for this object.boolean
isNullValueOK()
Is null an acceptable value for this option? Override this in subclasses where necessary.protected void
readAttributes(FreeColXMLReader xr)
Reads the attributes of this object from an XML stream.protected void
readChild(FreeColXMLReader xr)
Reads a single child object.protected void
readChildren(FreeColXMLReader xr)
Reads the children of this object from an XML stream.protected void
setValue(java.lang.String valueString, java.lang.String defaultValueString)
Sets the value of this option from the given string representation.void
setValue(UnitType value)
Sets the current value of thisUnitTypeOption
.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
getEnabledBy, getGroup, readOption, setGroup, 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, 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
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
value
private UnitType value
The option value.
-
addNone
private boolean addNone
Whether to add "none" to the list of choices to be generated.
-
selector
private UnitTypeOption.TypeSelector selector
Which choices to generate.
-
choices
private final java.util.List<UnitType> choices
A list of choices to provide to the UI.
-
ADD_NONE_TAG
private static final java.lang.String ADD_NONE_TAG
- See Also:
- Constant Field Values
-
CHOICE_TAG
private static final java.lang.String CHOICE_TAG
- See Also:
- Constant Field Values
-
GENERATE_TAG
private static final java.lang.String GENERATE_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
UnitTypeOption
public UnitTypeOption(Specification specification)
Creates a newUnitTypeOption
.- Parameters:
specification
- TheSpecification
to refer to.
-
UnitTypeOption
public UnitTypeOption(java.lang.String id, Specification specification)
Creates a newUnitTypeOption
.- Parameters:
id
- The object identifier.specification
- TheSpecification
to refer to.
-
-
Method Detail
-
addNone
public final boolean addNone()
Is "none" a valid choice for this option?- Returns:
- True if "none" is a valid choice.
-
getChoices
public final java.util.List<UnitType> getChoices()
Get the list of choices for this option.- Returns:
- A list of
UnitType
s.
-
getSelector
public final UnitTypeOption.TypeSelector getSelector()
Get the type of choices to generate.- Returns:
- The type of choices to generate.
-
cloneOption
public UnitTypeOption cloneOption()
Clone this option.- Specified by:
cloneOption
in interfaceOption<UnitType>
- Specified by:
cloneOption
in classAbstractOption<UnitType>
- Returns:
- A clone of this option.
-
getValue
public UnitType getValue()
Gets the current value of thisUnitTypeOption
.
-
setValue
public void setValue(UnitType value)
Sets the current value of thisUnitTypeOption
.
-
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. This method does nothing. Override it if the option has a suitable string representation.- Overrides:
setValue
in classAbstractOption<UnitType>
- Parameters:
valueString
- The string representation of the value of thisOption
.defaultValueString
- The string representation of the default value of thisOption
.
-
isNullValueOK
public boolean isNullValueOK()
Is null an acceptable value for this option? Override this in subclasses where necessary.- Overrides:
isNullValueOK
in classAbstractOption<UnitType>
- Returns:
- False.
-
generateChoices
public void generateChoices()
Generate the choices to provide to the UI. Override if the subclass needs to determine its choices dynamically.- Overrides:
generateChoices
in classAbstractOption<UnitType>
-
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<UnitType>
- 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
protected void readAttributes(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the attributes of this object from an XML stream.- Overrides:
readAttributes
in classAbstractOption<UnitType>
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
readChildren
protected 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
protected 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.
-
getXMLTagName
public java.lang.String getXMLTagName()
Get the serialization tag for this object.- Specified by:
getXMLTagName
in classFreeColObject
- Returns:
- The tag.
-
toString
public java.lang.String toString()
- Specified by:
toString
in interfaceOption<UnitType>
- Overrides:
toString
in classFreeColObject
-
-