Package net.sf.freecol.common.model
Class HistoryEvent
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.StringTemplate
-
- net.sf.freecol.common.model.HistoryEvent
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,ObjectWithId
public class HistoryEvent extends StringTemplate
A notable event in the history of a game.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
HistoryEvent.HistoryEventType
-
Nested classes/interfaces inherited from class net.sf.freecol.common.model.StringTemplate
StringTemplate.TemplateType
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
EVENT_TYPE_TAG
private HistoryEvent.HistoryEventType
eventType
The type of event.private static java.lang.String
PLAYER_ID_TAG
private java.lang.String
playerId
Which player gets credit for the event, if any.private int
score
Points for this event, if any.private static java.lang.String
SCORE_TAG
static java.lang.String
TAG
private Turn
turn
The turn in which the event took placeprivate static java.lang.String
TURN_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 HistoryEvent()
Trivial constructor to allow creation with Game.newInstance.HistoryEvent(FreeColXMLReader xr)
Create a new history event by reading a stream.HistoryEvent(Turn turn, HistoryEvent.HistoryEventType eventType, Player player)
Create a new history event of given turn and type.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends FreeColObject>
booleancopyIn(T other)
Copy another FreeColObject into this one if it is compatible.boolean
equals(java.lang.Object o)
HistoryEvent.HistoryEventType
getEventType()
Get the type of this history event.static HistoryEvent.HistoryEventType
getEventTypeFromStance(Stance stance)
Given a new stance, get the appropriate event type.java.lang.String
getPlayerId()
Get the id for the player that is credited with this event, if any.int
getScore()
Get the score for this event.Turn
getTurn()
Get the turn of this history event.java.lang.String
getXMLTagName()
Get the serialization tag for this object.int
hashCode()
protected void
readAttributes(FreeColXMLReader xr)
Reads the attributes of this object from an XML stream.void
setPlayerId(java.lang.String playerId)
Set the id for the player to credit for this event.void
setScore(int score)
Set the score for this event.java.lang.String
toString()
protected void
writeAttributes(FreeColXMLWriter xw)
Write the attributes of this object to a stream.-
Methods inherited from class net.sf.freecol.common.model.StringTemplate
add, add, addAmount, addName, addName, addName, addNamed, addNamed, addStringTemplate, addStringTemplate, addTagged, copy, entryList, getDefaultId, getReplacement, getTemplateType, isEmpty, key, key, label, name, readChild, readChildren, setDefaultId, setDefaultId, template, template, writeChildren
-
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, 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, getSpecification, getSuffix, getSuffix, hasAbility, hasAbility, hasAbility, 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, setSpecification, toXML, toXML, toXMLPartial, toXMLPartial
-
-
-
-
Field Detail
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
turn
private Turn turn
The turn in which the event took place
-
eventType
private HistoryEvent.HistoryEventType eventType
The type of event.
-
playerId
private java.lang.String playerId
Which player gets credit for the event, if any.
-
score
private int score
Points for this event, if any.
-
EVENT_TYPE_TAG
private static final java.lang.String EVENT_TYPE_TAG
- See Also:
- Constant Field Values
-
PLAYER_ID_TAG
private static final java.lang.String PLAYER_ID_TAG
- See Also:
- Constant Field Values
-
SCORE_TAG
private static final java.lang.String SCORE_TAG
- See Also:
- Constant Field Values
-
TURN_TAG
private static final java.lang.String TURN_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
HistoryEvent
public HistoryEvent()
Trivial constructor to allow creation with Game.newInstance.
-
HistoryEvent
public HistoryEvent(Turn turn, HistoryEvent.HistoryEventType eventType, Player player)
Create a new history event of given turn and type.- Parameters:
turn
- TheTurn
of the event.eventType
- TheEventType
.player
- An optionalPlayer
responsible for this event.
-
HistoryEvent
public HistoryEvent(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Create a new history event by reading a stream.- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
-
Method Detail
-
getTurn
public final Turn getTurn()
Get the turn of this history event.- Returns:
- The turn.
-
getEventType
public final HistoryEvent.HistoryEventType getEventType()
Get the type of this history event.- Returns:
- The event type.
-
getEventTypeFromStance
public static final HistoryEvent.HistoryEventType getEventTypeFromStance(Stance stance)
Given a new stance, get the appropriate event type.- Parameters:
stance
- The newStance
.- Returns:
- The corresponding event type.
-
getPlayerId
public final java.lang.String getPlayerId()
Get the id for the player that is credited with this event, if any.- Returns:
- The credited
Player
id.
-
setPlayerId
public void setPlayerId(java.lang.String playerId)
Set the id for the player to credit for this event.- Parameters:
playerId
- The new creditedPlayer
id.
-
getScore
public final int getScore()
Get the score for this event.- Returns:
- The score.
-
setScore
public void setScore(int score)
Set the score for this event.- Parameters:
score
- The new score for this event.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyIn
in classStringTemplate
- 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 classStringTemplate
- 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 classStringTemplate
- 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.- Overrides:
getXMLTagName
in classStringTemplate
- Returns:
- The tag.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classStringTemplate
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classStringTemplate
-
toString
public java.lang.String toString()
- Overrides:
toString
in classStringTemplate
-
-