Package net.sf.freecol.common.model
Class UnitChangeType
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColSpecObject
-
- net.sf.freecol.common.model.FreeColSpecObjectType
-
- net.sf.freecol.common.model.UnitChangeType
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,Named
,ObjectWithId
public class UnitChangeType extends FreeColSpecObjectType
The possible changes of a unit type.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CAPTURE
Changes due to the unit being captured.java.util.Map<UnitType,java.util.List<UnitTypeChange>>
changes
The individual unit changes valid for this change type.static java.lang.String
CLEAR_SKILL
Changes due to a clear-skill command.static java.lang.String
CONVERSION
Changes due to a unit being converted by missionaries.static java.lang.String
CREATION
Changes to be made immediately at creation of a unit.static java.lang.String
DEMOTION
Changes due to a unit being demoted after losing a battle.static java.lang.String
EDUCATION
Changes due to education.static java.lang.String
ENTER_COLONY
Changes when a unit begins to work in a colony.static java.lang.String
EXPERIENCE
Changes due to experience.static java.lang.String
FOUNDING_FATHER
Change when a founding father is elected.static java.lang.String
INDEPENDENCE
Changes at declaration of independence.static java.lang.String
LOST_CITY
Changes from exploring a lost city.static java.lang.String
NATIVES
Changes from living with the natives.private static java.lang.String
OWNER_CHANGE_TAG
private boolean
ownerChange
True if this type of change always implies a change of owner.static java.lang.String
PROMOTION
Changes due to the unit being promoted after winning a battle.static java.lang.String
TAG
static java.lang.String
UNDEAD
Changes due to the undead claiming the unit.-
Fields inherited from class net.sf.freecol.common.model.FreeColSpecObjectType
DELETE_TAG, EXTENDS_TAG, PRESERVE_TAG
-
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE_TAG, DEFAULT_CLASS_INDEX, fcoComparator, ID_ATTRIBUTE_TAG, logger, PARTIAL_ATTRIBUTE_TAG, VALUE_TAG
-
-
Constructor Summary
Constructors Constructor Description UnitChangeType(java.lang.String id, Specification specification)
Trivial constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addUnitTypeChange(UnitTypeChange uc)
Add a new change.<T extends FreeColObject>
booleancopyIn(T other)
Copy another FreeColObject into this one if it is compatible.void
deleteUnitChanges(UnitType from)
protected java.util.Map<UnitType,java.util.List<UnitTypeChange>>
getChanges()
Get the change map.boolean
getOwnerChange()
Get the owner change state.UnitTypeChange
getUnitChange(UnitType fromType, UnitType toType)
Get a specific unit change for this unit change type, a source unit type to change, and an optional destination unit type.java.util.List<UnitTypeChange>
getUnitChanges(UnitType from)
Get the unit changes possible from a given unit type.java.lang.String
getXMLTagName()
Get the serialization tag for this object.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
setChanges(java.util.Map<UnitType,java.util.List<UnitTypeChange>> changes)
Set the change map.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.model.FreeColSpecObjectType
addScope, appliesTo, copyScopes, getDescriptionKey, getFeatureContainer, getIndex, getNameKey, getScopeList, getScopes, isAbstractType, removeScope, setIndex
-
Methods inherited from class net.sf.freecol.common.model.FreeColSpecObject
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, 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
-
-
-
-
Field Detail
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
CAPTURE
public static final java.lang.String CAPTURE
Changes due to the unit being captured.- See Also:
- Constant Field Values
-
CLEAR_SKILL
public static final java.lang.String CLEAR_SKILL
Changes due to a clear-skill command.- See Also:
- Constant Field Values
-
CONVERSION
public static final java.lang.String CONVERSION
Changes due to a unit being converted by missionaries.- See Also:
- Constant Field Values
-
CREATION
public static final java.lang.String CREATION
Changes to be made immediately at creation of a unit.- See Also:
- Constant Field Values
-
DEMOTION
public static final java.lang.String DEMOTION
Changes due to a unit being demoted after losing a battle.- See Also:
- Constant Field Values
-
EDUCATION
public static final java.lang.String EDUCATION
Changes due to education.- See Also:
- Constant Field Values
-
ENTER_COLONY
public static final java.lang.String ENTER_COLONY
Changes when a unit begins to work in a colony. This is not in the standard spec but in the convertUpgrade mod. However it needs coding support to work.- See Also:
- Constant Field Values
-
EXPERIENCE
public static final java.lang.String EXPERIENCE
Changes due to experience.- See Also:
- Constant Field Values
-
FOUNDING_FATHER
public static final java.lang.String FOUNDING_FATHER
Change when a founding father is elected.- See Also:
- Constant Field Values
-
INDEPENDENCE
public static final java.lang.String INDEPENDENCE
Changes at declaration of independence.- See Also:
- Constant Field Values
-
LOST_CITY
public static final java.lang.String LOST_CITY
Changes from exploring a lost city.- See Also:
- Constant Field Values
-
NATIVES
public static final java.lang.String NATIVES
Changes from living with the natives.- See Also:
- Constant Field Values
-
PROMOTION
public static final java.lang.String PROMOTION
Changes due to the unit being promoted after winning a battle.- See Also:
- Constant Field Values
-
UNDEAD
public static final java.lang.String UNDEAD
Changes due to the undead claiming the unit.- See Also:
- Constant Field Values
-
changes
public final java.util.Map<UnitType,java.util.List<UnitTypeChange>> changes
The individual unit changes valid for this change type.
-
ownerChange
private boolean ownerChange
True if this type of change always implies a change of owner.
-
OWNER_CHANGE_TAG
private static final java.lang.String OWNER_CHANGE_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
UnitChangeType
public UnitChangeType(java.lang.String id, Specification specification)
Trivial constructor.- Parameters:
id
- The object identifier.specification
- TheSpecification
to use.
-
-
Method Detail
-
getOwnerChange
public boolean getOwnerChange()
Get the owner change state.- Returns:
- True if this type change is expected to be accompanied by an owner change.
-
getChanges
protected java.util.Map<UnitType,java.util.List<UnitTypeChange>> getChanges()
Get the change map.- Returns:
- The map of unit type to eligible changes.
-
setChanges
protected void setChanges(java.util.Map<UnitType,java.util.List<UnitTypeChange>> changes)
Set the change map.- Parameters:
changes
- The new map of unit type to eligible changes.
-
addUnitTypeChange
public void addUnitTypeChange(UnitTypeChange uc)
Add a new change. Public for the test suite.- Parameters:
uc
- TheUnitTypeChange
to add.
-
getUnitChanges
public java.util.List<UnitTypeChange> getUnitChanges(UnitType from)
Get the unit changes possible from a given unit type.- Parameters:
from
- The sourceUnitType
.- Returns:
- A list of
UnitChange
s.
-
getUnitChange
public UnitTypeChange getUnitChange(UnitType fromType, UnitType toType)
Get a specific unit change for this unit change type, a source unit type to change, and an optional destination unit type.- Parameters:
fromType
- TheUnitType
to change from.toType
- An optionalUnitType
to change to.- Returns:
- The
UnitChange
found, or null if the change is impossible.
-
deleteUnitChanges
public void deleteUnitChanges(UnitType from)
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyIn
in classFreeColSpecObjectType
- Type Parameters:
T
- TheFreeColObject
subclass of the object to copy in.- Parameters:
other
- The other object.- Returns:
- True if the copy in is succesful.
-
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 classFreeColObject
- 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 classFreeColSpecObjectType
- 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 classFreeColSpecObjectType
- 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 classFreeColSpecObjectType
- 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 classFreeColSpecObjectType
- 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()
- Overrides:
toString
in classFreeColSpecObjectType
-
-