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
TheOperandclass 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 classOperand.OperandTypestatic classOperand.ScopeLevel
-
Field Summary
Fields Modifier and Type Field Description private static java.util.logging.Loggerloggerprivate static java.lang.StringOLD_OPERAND_TYPE_TAGprivate static java.lang.StringOLD_SCOPE_LEVEL_TAGprivate static java.lang.StringOPERAND_TYPE_TAGprivate Operand.OperandTypeoperandTypeThe type of object the operand really represents.private static java.lang.StringSCOPE_LEVEL_TAGprivate Operand.ScopeLevelscopeLevelHow broadly to apply the operand.private java.lang.IntegervalueThe 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 newOperandinstance.protectedOperand(FreeColXMLReader xr)Create a new operand by reading a stream.Operand(Operand.OperandType operandType, Operand.ScopeLevel scopeLevel)Creates a newOperandinstance.
-
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.booleanequals(java.lang.Object o)Operand.OperandTypegetOperandType()Gets the operand type.Operand.ScopeLevelgetScopeLevel()Gets the scope level.java.lang.IntegergetValue()Gets the operand value.java.lang.IntegergetValue(Game game)Gets the operand value if it is applicable to the given Game.java.lang.IntegergetValue(Player player)Gets the operand value if it is applicable to the given Player.java.lang.IntegergetValue(Settlement settlement)Gets the operand value if it is applicable to the given Settlement.inthashCode()private java.lang.IntegerourCount(java.util.Collection<? extends FreeColObject> objects)Count the number of objects in a list that this operand is applicable to.protected voidreadAttributes(FreeColXMLReader xr)Reads the attributes of this object from an XML stream.voidsetOperandType(Operand.OperandType newOperandType)Set the operand type.voidsetScopeLevel(Operand.ScopeLevel newScopeLevel)Sets the scope level.voidsetValue(java.lang.Integer newValue)Sets the operand value.java.lang.StringtoString()protected voidwriteAttributes(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 newOperandinstance.- Parameters:
value- The initial operand value.
-
Operand
public Operand(Operand.OperandType operandType, Operand.ScopeLevel scopeLevel)
Creates a newOperandinstance.- Parameters:
operandType- TheOperandTypeto use.scopeLevel- TheScopeLevelto use.
-
Operand
protected Operand(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Create a new operand by reading a stream.- Parameters:
xr- TheFreeColXMLReaderto 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- TheGameto 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- ThePlayerto 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- TheSettlementto 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:
writeAttributesin classScope- 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 classScope- Parameters:
xr- TheFreeColXMLReaderto read from.- Throws:
javax.xml.stream.XMLStreamException- if there is a problem reading the stream.
-
-