Package net.sf.freecol.common.option
Class AbstractUnitOption
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColSpecObject
-
- net.sf.freecol.common.option.AbstractOption<AbstractUnit>
-
- net.sf.freecol.common.option.AbstractUnitOption
-
- All Implemented Interfaces:
java.lang.Cloneable
,java.lang.Comparable<FreeColObject>
,ObjectWithId
,Option<AbstractUnit>
public class AbstractUnitOption extends AbstractOption<AbstractUnit>
Represents an option where the valid choice is an AbstractUnit.
-
-
Field Summary
Fields Modifier and Type Field Description private static UnitTypeOption.TypeSelector
DEFAULT_SELECTOR
private static java.util.logging.Logger
logger
private static java.lang.String
NATION_TYPE_TAG
private NationType
nationType
An optional nation type for the unit.private static java.lang.String
NUMBER_TAG
private IntegerOption
numberOption
An Option to determine the number of the AbstractUnit.private static java.lang.String
ROLE_TAG
private StringOption
roleOption
An Option to determine the Role of the AbstractUnit.static java.lang.String
TAG
private static java.lang.String
UNIT_TYPE_TAG
private UnitTypeOption
unitTypeOption
An Option to determine the UnitType of the AbstractUnit.private AbstractUnit
value
The value of this option.-
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 AbstractUnitOption(java.lang.String id, Specification specification)
Creates a newAbstractUnitOption
.AbstractUnitOption(Specification specification)
Creates a newAbstractUnitOption
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AbstractUnitOption
cloneOption()
Clone this option.void
generateChoices()
Generate the choices to provide to the UI.NationType
getNationType()
Get the nation type.IntegerOption
getNumber()
Get the number option.StringOption
getRole()
Get the role option.UnitTypeOption
getUnitType()
Get the unit type option.AbstractUnit
getValue()
Gets the value of this option.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.void
readChild(FreeColXMLReader xr)
Reads a single child object.void
readChildren(FreeColXMLReader xr)
Reads the children of this object from an XML stream.private void
requireNumberOption()
private void
requireRoleOption()
private void
requireUnitTypeOption()
void
setValue(AbstractUnit value)
Sets the value of this option.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, 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, 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
-
DEFAULT_SELECTOR
private static final UnitTypeOption.TypeSelector DEFAULT_SELECTOR
-
value
private AbstractUnit value
The value of this option.
-
unitTypeOption
private UnitTypeOption unitTypeOption
An Option to determine the UnitType of the AbstractUnit.
-
roleOption
private StringOption roleOption
An Option to determine the Role of the AbstractUnit.
-
numberOption
private IntegerOption numberOption
An Option to determine the number of the AbstractUnit.
-
nationType
private NationType nationType
An optional nation type for the unit.
-
NATION_TYPE_TAG
private static final java.lang.String NATION_TYPE_TAG
- See Also:
- Constant Field Values
-
NUMBER_TAG
private static final java.lang.String NUMBER_TAG
- See Also:
- Constant Field Values
-
ROLE_TAG
private static final java.lang.String ROLE_TAG
- See Also:
- Constant Field Values
-
UNIT_TYPE_TAG
private static final java.lang.String UNIT_TYPE_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AbstractUnitOption
public AbstractUnitOption(Specification specification)
Creates a newAbstractUnitOption
.- Parameters:
specification
- TheSpecification
to refer to.
-
AbstractUnitOption
public AbstractUnitOption(java.lang.String id, Specification specification)
Creates a newAbstractUnitOption
.- Parameters:
id
- The object identifier.specification
- TheSpecification
to refer to.
-
-
Method Detail
-
requireUnitTypeOption
private void requireUnitTypeOption()
-
requireRoleOption
private void requireRoleOption()
-
requireNumberOption
private void requireNumberOption()
-
getUnitType
public final UnitTypeOption getUnitType()
Get the unit type option.- Returns:
- The
UnitTypeOption
containing the unit type.
-
getRole
public final StringOption getRole()
Get the role option.- Returns:
- The
StringOption
containing the role.
-
getNumber
public final IntegerOption getNumber()
Get the number option.- Returns:
- The
IntegerOption
containing the number.
-
getNationType
public final NationType getNationType()
Get the nation type.- Returns:
- The optional
NationType
.
-
cloneOption
public AbstractUnitOption cloneOption()
Clone this option.- Specified by:
cloneOption
in interfaceOption<AbstractUnit>
- Specified by:
cloneOption
in classAbstractOption<AbstractUnit>
- Returns:
- A clone of this option.
-
getValue
public AbstractUnit getValue()
Gets the value of this option.- Specified by:
getValue
in interfaceOption<AbstractUnit>
- Specified by:
getValue
in classAbstractOption<AbstractUnit>
- Returns:
- The value of this
Option
.
-
setValue
public void setValue(AbstractUnit value)
Sets the value of this option.- Specified by:
setValue
in interfaceOption<AbstractUnit>
- Specified by:
setValue
in classAbstractOption<AbstractUnit>
- Parameters:
value
- The new 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<AbstractUnit>
- 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<AbstractUnit>
-
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<AbstractUnit>
- 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<AbstractUnit>
- 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.
-
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<AbstractUnit>
- Overrides:
toString
in classFreeColObject
-
-