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.StringCAPTUREChanges due to the unit being captured.java.util.Map<UnitType,java.util.List<UnitTypeChange>>changesThe individual unit changes valid for this change type.static java.lang.StringCLEAR_SKILLChanges due to a clear-skill command.static java.lang.StringCONVERSIONChanges due to a unit being converted by missionaries.static java.lang.StringCREATIONChanges to be made immediately at creation of a unit.static java.lang.StringDEMOTIONChanges due to a unit being demoted after losing a battle.static java.lang.StringEDUCATIONChanges due to education.static java.lang.StringENTER_COLONYChanges when a unit begins to work in a colony.static java.lang.StringEXPERIENCEChanges due to experience.static java.lang.StringFOUNDING_FATHERChange when a founding father is elected.static java.lang.StringINDEPENDENCEChanges at declaration of independence.static java.lang.StringLOST_CITYChanges from exploring a lost city.static java.lang.StringNATIVESChanges from living with the natives.private static java.lang.StringOWNER_CHANGE_TAGprivate booleanownerChangeTrue if this type of change always implies a change of owner.static java.lang.StringPROMOTIONChanges due to the unit being promoted after winning a battle.static java.lang.StringTAGstatic java.lang.StringUNDEADChanges 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 voidaddUnitTypeChange(UnitTypeChange uc)Add a new change.<T extends FreeColObject>
booleancopyIn(T other)Copy another FreeColObject into this one if it is compatible.voiddeleteUnitChanges(UnitType from)protected java.util.Map<UnitType,java.util.List<UnitTypeChange>>getChanges()Get the change map.booleangetOwnerChange()Get the owner change state.UnitTypeChangegetUnitChange(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.StringgetXMLTagName()Get the serialization tag for this object.protected voidreadAttributes(FreeColXMLReader xr)Reads the attributes of this object from an XML stream.protected voidreadChild(FreeColXMLReader xr)Reads a single child object.protected voidreadChildren(FreeColXMLReader xr)Reads the children of this object from an XML stream.protected voidsetChanges(java.util.Map<UnitType,java.util.List<UnitTypeChange>> changes)Set the change map.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.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- TheSpecificationto 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- TheUnitTypeChangeto 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
UnitChanges.
-
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- TheUnitTypeto change from.toType- An optionalUnitTypeto change to.- Returns:
- The
UnitChangefound, 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:
copyInin classFreeColSpecObjectType- Type Parameters:
T- TheFreeColObjectsubclass 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:
writeAttributesin classFreeColObject- 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 classFreeColSpecObjectType- Parameters:
xw- TheFreeColXMLWriterto 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:
readAttributesin classFreeColSpecObjectType- Parameters:
xr- TheFreeColXMLReaderto 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:
readChildrenin classFreeColSpecObjectType- Parameters:
xr- TheFreeColXMLReaderto 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:
readChildin classFreeColSpecObjectType- Parameters:
xr- TheFreeColXMLReaderto 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:
getXMLTagNamein classFreeColObject- Returns:
- The tag.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classFreeColSpecObjectType
-
-