net.sf.freecol.common.model
Class Limit

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColObject
      extended by net.sf.freecol.common.model.FreeColGameObjectType
          extended by net.sf.freecol.common.model.Limit

public final class Limit
extends FreeColGameObjectType

The Limit class encapsulates a limit on the availability of FreeColObjects. It consists of a left hand side, an operator and a right hand side, and can be used to limit the number of units of a particular type (e.g. wagon trains) to the number of a player's colonies, for example. The left hand side must apply to the object on which a limit is to be placed.


Nested Class Summary
static class Limit.Operator
           
 
Field Summary
private  Operand leftHandSide
          Describe leftHandSide here.
private  Limit.Operator operator
          Describe operator here.
private  Operand rightHandSide
          Describe rightHandSide here.
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, INFINITY, logger, NO_ID, PARTIAL_ATTRIBUTE, UNDEFINED, VALUE_TAG
 
Constructor Summary
Limit(Specification specification)
           
Limit(java.lang.String id, Operand lhs, Limit.Operator op, Operand rhs)
           
 
Method Summary
 boolean appliesTo(FreeColObject object)
           
 boolean evaluate(Game game)
          Describe evaluate method here.
private  boolean evaluate(java.lang.Integer lhs, java.lang.Integer rhs)
           
 boolean evaluate(Player player)
          Describe evaluate method here.
 boolean evaluate(Settlement settlement)
          Describe evaluate method here.
 Operand getLeftHandSide()
          Get the LeftHandSide value.
 Limit.Operator getOperator()
          Get the Operator value.
 Operand getRightHandSide()
          Get the RightHandSide value.
static java.lang.String getXMLElementTagName()
          Returns the XML tag name for this element.
 boolean hasOperandType(Operand.OperandType type)
          Returns true if at least one of the Operands has the given OperandType.
protected  void readAttributes(javax.xml.stream.XMLStreamReader in)
          Reads the attributes of this object from an XML stream.
protected  void readChild(javax.xml.stream.XMLStreamReader in)
          Reads a child object.
 void setLeftHandSide(Operand newLeftHandSide)
          Set the LeftHandSide value.
 void setOperator(Limit.Operator newOperator)
          Set the Operator value.
 void setRightHandSide(Operand newRightHandSide)
          Set the RightHandSide value.
 java.lang.String toString()
          Use only for debugging purposes! A human-readable and localized name is returned by getName().
 void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
          This method writes an XML-representation of this object to the given stream.
protected  void writeAttributes(javax.xml.stream.XMLStreamWriter out)
          Write the attributes of this object to a stream.
protected  void writeChildren(javax.xml.stream.XMLStreamWriter out)
          Write the children of this object to a stream.
 
Methods inherited from class net.sf.freecol.common.model.FreeColGameObjectType
addAbility, addModifier, applyDifficultyLevel, getDescriptionKey, getFeatureContainer, getIndex, getModifierIndex, getModifierIndex, getModifierSet, getNameKey, hasAbility, hasAbility, isAbstractType, readChildren, setAbstractType, setFeatureContainer, setIndex, setModifierIndex, toXMLImpl
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getId, getPropertyChangeListeners, getPropertyChangeListeners, getSpecification, hasAttribute, hasListeners, readAttributes, readChild, readChildren, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXML, readFromXMLElement, readFromXMLImpl, readFromXMLImpl, readFromXMLPartialImpl, removePropertyChangeListener, removePropertyChangeListener, save, save, setId, setSpecification, toXML, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, toXMLPartialImpl, writeAttribute
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

operator

private Limit.Operator operator
Describe operator here.


leftHandSide

private Operand leftHandSide
Describe leftHandSide here.


rightHandSide

private Operand rightHandSide
Describe rightHandSide here.

Constructor Detail

Limit

public Limit(Specification specification)

Limit

public Limit(java.lang.String id,
             Operand lhs,
             Limit.Operator op,
             Operand rhs)
Method Detail

getOperator

public Limit.Operator getOperator()
Get the Operator value.

Returns:
an Operator value

setOperator

public void setOperator(Limit.Operator newOperator)
Set the Operator value.

Parameters:
newOperator - The new Operator value.

getLeftHandSide

public Operand getLeftHandSide()
Get the LeftHandSide value.

Returns:
an Operand value

setLeftHandSide

public void setLeftHandSide(Operand newLeftHandSide)
Set the LeftHandSide value.

Parameters:
newLeftHandSide - The new LeftHandSide value.

getRightHandSide

public Operand getRightHandSide()
Get the RightHandSide value.

Returns:
an Operand value

setRightHandSide

public void setRightHandSide(Operand newRightHandSide)
Set the RightHandSide value.

Parameters:
newRightHandSide - The new RightHandSide value.

appliesTo

public boolean appliesTo(FreeColObject object)

evaluate

public boolean evaluate(Game game)
Describe evaluate method here.

Parameters:
game - a Game value
Returns:
a boolean value

evaluate

public boolean evaluate(Player player)
Describe evaluate method here.

Parameters:
player - a Player value
Returns:
a boolean value

evaluate

public boolean evaluate(Settlement settlement)
Describe evaluate method here.

Parameters:
settlement - a Settlement value
Returns:
a boolean value

hasOperandType

public boolean hasOperandType(Operand.OperandType type)
Returns true if at least one of the Operands has the given OperandType.

Parameters:
type - an OperandType value
Returns:
a boolean value

evaluate

private boolean evaluate(java.lang.Integer lhs,
                         java.lang.Integer rhs)

toXMLImpl

public void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
               throws javax.xml.stream.XMLStreamException
This method writes an XML-representation of this object to the given stream.

Overrides:
toXMLImpl in class FreeColGameObjectType
Parameters:
out - The target stream.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.

writeAttributes

protected void writeAttributes(javax.xml.stream.XMLStreamWriter out)
                        throws javax.xml.stream.XMLStreamException
Write the attributes of this object to a stream.

Overrides:
writeAttributes in class FreeColObject
Parameters:
out - The target stream.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.

writeChildren

protected void writeChildren(javax.xml.stream.XMLStreamWriter out)
                      throws javax.xml.stream.XMLStreamException
Write the children of this object to a stream.

Overrides:
writeChildren in class FreeColGameObjectType
Parameters:
out - The target stream.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.

readAttributes

protected void readAttributes(javax.xml.stream.XMLStreamReader in)
                       throws javax.xml.stream.XMLStreamException
Reads the attributes of this object from an XML stream.

Overrides:
readAttributes in class FreeColGameObjectType
Parameters:
in - The XML input stream.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.

readChild

protected void readChild(javax.xml.stream.XMLStreamReader in)
                  throws javax.xml.stream.XMLStreamException
Reads a child object.

Overrides:
readChild in class FreeColGameObjectType
Parameters:
in - The XML stream to read.
Throws:
javax.xml.stream.XMLStreamException - if an error occurs

toString

public java.lang.String toString()
Description copied from class: FreeColGameObjectType
Use only for debugging purposes! A human-readable and localized name is returned by getName().

Overrides:
toString in class FreeColGameObjectType

getXMLElementTagName

public static java.lang.String getXMLElementTagName()
Returns the XML tag name for this element.

Returns:
"limit".