Package net.sf.freecol.common.model
Class Event
- 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.Event
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,Named
,ObjectWithId
public class Event extends FreeColSpecObjectType
A special game event.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,Limit>
limits
Limits on this event.private static java.lang.String
OLD_SCORE_VALUE_TAG
private static java.lang.String
SCORE_VALUE_TAG
private int
scoreValue
The score value of this event.static java.lang.String
TAG
private java.lang.String
value
A restriction on the scope of the event.-
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 Event(java.lang.String id, Specification specification)
Create a new event.Event(FreeColXMLReader xr, Specification specification)
Create a new event.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addLimit(Limit limit)
Add a limit.<T extends FreeColObject>
booleancopyIn(T other)
Copy another FreeColObject into this one if it is compatible.Limit
getLimit(java.lang.String id)
Gets a particular limit by identifier.protected java.util.Map<java.lang.String,Limit>
getLimits()
Get the limit map.java.util.Collection<Limit>
getLimitValues()
Get the limits on this event.int
getScoreValue()
Get the score value of this event.java.lang.String
getValue()
Gets the event restriction.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
setLimits(java.util.Map<java.lang.String,Limit> limits)
Set the limits on this event.void
setScoreValue(int newScoreValue)
Set the score value of this event.void
setValue(java.lang.String newValue)
Sets the event restriction.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, toString
-
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
-
value
private java.lang.String value
A restriction on the scope of the event.
-
scoreValue
private int scoreValue
The score value of this event.
-
limits
private java.util.Map<java.lang.String,Limit> limits
Limits on this event.
-
SCORE_VALUE_TAG
private static final java.lang.String SCORE_VALUE_TAG
- See Also:
- Constant Field Values
-
OLD_SCORE_VALUE_TAG
private static final java.lang.String OLD_SCORE_VALUE_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Event
public Event(java.lang.String id, Specification specification)
Create a new event.- Parameters:
id
- The object identifier.specification
- TheSpecification
to refer to.
-
Event
public Event(FreeColXMLReader xr, Specification specification) throws javax.xml.stream.XMLStreamException
Create a new event.- Parameters:
xr
- TheFreeColXMLReader
to read from.specification
- TheSpecification
to refer to.- Throws:
javax.xml.stream.XMLStreamException
- if there a problem reading the stream.
-
-
Method Detail
-
getValue
public final java.lang.String getValue()
Gets the event restriction.- Returns:
- The restriction.
-
setValue
public final void setValue(java.lang.String newValue)
Sets the event restriction.- Parameters:
newValue
- The new event restriction.
-
getScoreValue
public final int getScoreValue()
Get the score value of this event.- Returns:
- The score value.
-
setScoreValue
public final void setScoreValue(int newScoreValue)
Set the score value of this event.- Parameters:
newScoreValue
- The new score value.
-
getLimits
protected java.util.Map<java.lang.String,Limit> getLimits()
Get the limit map.- Returns:
- The map of the limits.
-
setLimits
protected void setLimits(java.util.Map<java.lang.String,Limit> limits)
Set the limits on this event.- Parameters:
limits
- A new limits map.
-
getLimitValues
public final java.util.Collection<Limit> getLimitValues()
Get the limits on this event.- Returns:
- A list of limits.
-
getLimit
public final Limit getLimit(java.lang.String id)
Gets a particular limit by identifier.- Parameters:
id
- The object identifier.- Returns:
- The corresponding
Limit
or null if not found.
-
addLimit
private void addLimit(Limit limit)
Add a limit.- Parameters:
limit
- TheLimit
to add.
-
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.
-
-