Package net.sf.freecol.common.model
Class Operand
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.Scope
-
- net.sf.freecol.common.model.Operand
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,ObjectWithId
public class Operand extends Scope
TheOperand
class implements Operands to be used in relations, such as the Limit class. The OperandType specifies which types of objects will be considered, and the ScopeLevel specifies the level at which these objects are to be selected. If the ScopeLevel is PLAYER, for example, and the OperandType is UNITS, then all units owned by a particular player will be considered. Since the class inherits from Scope, the choice of objects can be further refined by specifying type, ability or method. However, the return value of the method must be an Integer (or int), since this value will be returned as the value of the Operand itself if the OperandType is NONE.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Operand.OperandType
static class
Operand.ScopeLevel
-
Field Summary
Fields Modifier and Type Field Description private static java.util.logging.Logger
logger
private static java.lang.String
OLD_OPERAND_TYPE_TAG
private static java.lang.String
OLD_SCOPE_LEVEL_TAG
private static java.lang.String
OPERAND_TYPE_TAG
private Operand.OperandType
operandType
The type of object the operand really represents.private static java.lang.String
SCOPE_LEVEL_TAG
private Operand.ScopeLevel
scopeLevel
How broadly to apply the operand.private java.lang.Integer
value
The operand amount.-
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 Modifier Constructor Description Operand()
Deliberately empty constructor.Operand(int value)
Creates a newOperand
instance.protected
Operand(FreeColXMLReader xr)
Create a new operand by reading a stream.Operand(Operand.OperandType operandType, Operand.ScopeLevel scopeLevel)
Creates a newOperand
instance.
-
Method Summary
All 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)
Operand.OperandType
getOperandType()
Gets the operand type.Operand.ScopeLevel
getScopeLevel()
Gets the scope level.java.lang.Integer
getValue()
Gets the operand value.java.lang.Integer
getValue(Game game)
Gets the operand value if it is applicable to the given Game.java.lang.Integer
getValue(Player player)
Gets the operand value if it is applicable to the given Player.java.lang.Integer
getValue(Settlement settlement)
Gets the operand value if it is applicable to the given Settlement.int
hashCode()
private java.lang.Integer
ourCount(java.util.Collection<? extends FreeColObject> objects)
Count the number of objects in a list that this operand is applicable to.protected void
readAttributes(FreeColXMLReader xr)
Reads the attributes of this object from an XML stream.void
setOperandType(Operand.OperandType newOperandType)
Set the operand type.void
setScopeLevel(Operand.ScopeLevel newScopeLevel)
Sets the scope level.void
setValue(java.lang.Integer newValue)
Sets the operand value.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.Scope
appliesTo, getAbilityId, getAbilityValue, getFeatureString, getKey, getMatchNegated, getMethodName, getMethodValue, getType, getXMLTagName, setAbilityId, setAbilityValue, setMatchesNull, setMatchNegated, setMethodName, setMethodValue, setType
-
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, readChild, readChildren, readFromXML, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setGame, setId, setSpecification, toXML, toXML, toXMLPartial, toXMLPartial, writeChildren
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
operandType
private Operand.OperandType operandType
The type of object the operand really represents.
-
scopeLevel
private Operand.ScopeLevel scopeLevel
How broadly to apply the operand.
-
value
private java.lang.Integer value
The operand amount.
-
OPERAND_TYPE_TAG
private static final java.lang.String OPERAND_TYPE_TAG
- See Also:
- Constant Field Values
-
SCOPE_LEVEL_TAG
private static final java.lang.String SCOPE_LEVEL_TAG
- See Also:
- Constant Field Values
-
OLD_OPERAND_TYPE_TAG
private static final java.lang.String OLD_OPERAND_TYPE_TAG
- See Also:
- Constant Field Values
-
OLD_SCOPE_LEVEL_TAG
private static final java.lang.String OLD_SCOPE_LEVEL_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Operand
public Operand()
Deliberately empty constructor.
-
Operand
public Operand(int value)
Creates a newOperand
instance.- Parameters:
value
- The initial operand value.
-
Operand
public Operand(Operand.OperandType operandType, Operand.ScopeLevel scopeLevel)
Creates a newOperand
instance.- Parameters:
operandType
- TheOperandType
to use.scopeLevel
- TheScopeLevel
to use.
-
Operand
protected Operand(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Create a new operand by reading a stream.- Parameters:
xr
- TheFreeColXMLReader
to read.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
-
Method Detail
-
getOperandType
public final Operand.OperandType getOperandType()
Gets the operand type.- Returns:
- The
OperandType
.
-
setOperandType
public final void setOperandType(Operand.OperandType newOperandType)
Set the operand type.- Parameters:
newOperandType
- The newOperandType
.
-
getScopeLevel
public final Operand.ScopeLevel getScopeLevel()
Gets the scope level.- Returns:
- The scope level.
-
setScopeLevel
public final void setScopeLevel(Operand.ScopeLevel newScopeLevel)
Sets the scope level.- Parameters:
newScopeLevel
- The newScopeLevel
.
-
getValue
public final java.lang.Integer getValue()
Gets the operand value.- Returns:
- The operand value.
-
setValue
public final void setValue(java.lang.Integer newValue)
Sets the operand value.- Parameters:
newValue
- The new value.
-
ourCount
private java.lang.Integer ourCount(java.util.Collection<? extends FreeColObject> objects)
Count the number of objects in a list that this operand is applicable to.- Parameters:
objects
- The list of objects to check.- Returns:
- The number of applicable objects.
-
getValue
public java.lang.Integer getValue(Game game)
Gets the operand value if it is applicable to the given Game.- Parameters:
game
- TheGame
to check.- Returns:
- The operand value or null if inapplicable.
-
getValue
public java.lang.Integer getValue(Player player)
Gets the operand value if it is applicable to the given Player.- Parameters:
player
- ThePlayer
to check.- Returns:
- The operand value, or null if inapplicable.
-
getValue
public java.lang.Integer getValue(Settlement settlement)
Gets the operand value if it is applicable to the given Settlement.- Parameters:
settlement
- TheSettlement
to check.- Returns:
- The operand value, or null if inapplicable.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.
-
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 classScope
- 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 classScope
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
-