net.sf.magicproject.expression
Class Expression

java.lang.Object
  extended by net.sf.magicproject.expression.Expression
Direct Known Subclasses:
AbstractValue, BinaryExpression, CardColors, CardTypes, Counter, DeckCounter, HighestAmong, IfThenElse, IntValue, LowestAmong, ManaPaid, ObjectValue, Position, ReferenceValue, RegisterAccess, SavedListExpression, StringMethod, TestOn, ToCode, ToIndex, UnaryExpression

public abstract class Expression
extends java.lang.Object

This class represents an expression. Value type is int by default but it can also be an object. If the method getObject() is not overridden, the given object value will be the Integer representation of the int value.

Since:
0.80
Author:
Fabrice Daugan

Method Summary
 boolean canBePreempted()
          Return true if the associated value can be evaluated without ability context.
 void extractTriggeredEvents(java.util.List<MEventListener> res, MCard source, Test globalTest)
          Adds to the specified list, the events modifying the result of this test.
 Expression getConstraintExpression(java.util.Map<java.lang.String,Expression> values)
          Returns this expression where values depending on values of this action have been replaced.
 java.lang.Object getObject(Ability ability, Targetable tested, ContextEventListener context)
          Returns the object value of this expression.
 java.lang.Class<?> getObjectClass()
          Returns the class of the object value of this expression.
 int getPreemptionValue(Ability ability, Targetable tested, ContextEventListener context)
          Returns the integer value of this expression exactly as it will be when the ability will be executed.
abstract  int getValue(Ability ability, Targetable tested, ContextEventListener context)
          Returns the integer value of this expression
 boolean isConstant()
          Is this expression is a constant.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getObject

public java.lang.Object getObject(Ability ability,
                                  Targetable tested,
                                  ContextEventListener context)
Returns the object value of this expression.

Parameters:
ability - the ability owning this test. The card component of this ability should correspond tho the card owning this test too.
tested - the tested card
context - the context event listener
Returns:
the object value of this expression

getObjectClass

public java.lang.Class<?> getObjectClass()
Returns the class of the object value of this expression.

Returns:
the class of the object value of this expression

getValue

public abstract int getValue(Ability ability,
                             Targetable tested,
                             ContextEventListener context)
Returns the integer value of this expression

Parameters:
ability - is the ability owning this test. The card component of this ability should correspond to the card owning this test too.
tested - the tested card
context - is the context attached to this test.
Returns:
the integer value of this expression

getPreemptionValue

public int getPreemptionValue(Ability ability,
                              Targetable tested,
                              ContextEventListener context)
Returns the integer value of this expression exactly as it will be when the ability will be executed.

Parameters:
ability - is the ability owning this test. The card component of this ability should correspond to the card owning this test too.
tested - the tested card
context - is the context attached to this test.
Returns:
the integer value of this expression. Returns -1 if is not preemptable.

getConstraintExpression

public Expression getConstraintExpression(java.util.Map<java.lang.String,Expression> values)
Returns this expression where values depending on values of this action have been replaced.

Parameters:
values - are referecable values.
Returns:
a parsed test.
Since:
0.85

extractTriggeredEvents

public void extractTriggeredEvents(java.util.List<MEventListener> res,
                                   MCard source,
                                   Test globalTest)
Adds to the specified list, the events modifying the result of this test.

Parameters:
res - is the list of events to fill
source - is the card source of event
globalTest - the optional global test to include in the event test.

isConstant

public boolean isConstant()
Is this expression is a constant.

Returns:
true if this expression is a constant.

canBePreempted

public boolean canBePreempted()
Return true if the associated value can be evaluated without ability context.

Returns:
true if the associated value can be evaluated without ability context.


Copyright © 2003-2007 Magic-Project. All Rights Reserved.