Class Operand

  • All Implemented Interfaces:
    java.lang.Comparable<FreeColObject>, ObjectWithId

    public class Operand
    extends Scope
    The Operand 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.
    • Field Detail

      • logger

        private static final java.util.logging.Logger logger
      • operandType

        private Operand.OperandType operandType
        The type of object the operand really represents.
      • 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
      • 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 new Operand instance.
        Parameters:
        value - The initial operand value.
      • Operand

        public Operand​(Operand.OperandType operandType,
                       Operand.ScopeLevel scopeLevel)
        Creates a new Operand instance.
        Parameters:
        operandType - The OperandType to use.
        scopeLevel - The ScopeLevel to use.
      • Operand

        protected Operand​(FreeColXMLReader xr)
                   throws javax.xml.stream.XMLStreamException
        Create a new operand by reading a stream.
        Parameters:
        xr - The FreeColXMLReader 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 new OperandType.
      • 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 new ScopeLevel.
      • 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 - The Game 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 - The Player 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 - The Settlement 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.
        Overrides:
        copyIn in class Scope
        Type Parameters:
        T - The FreeColObject 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 class Scope
        Parameters:
        xw - The FreeColXMLWriter 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 class Scope
        Parameters:
        xr - The FreeColXMLReader to read from.
        Throws:
        javax.xml.stream.XMLStreamException - if there is a problem reading the stream.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class Scope
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Scope
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class Scope