org.moremotion.evaluator
Interface SymbolResolver

All Known Implementing Classes:
MMSymbolResolver

public interface SymbolResolver

Defines an interface to provide the data types and the values of the symbols. The objects of the classes that implement this interface can be introduced to Expression class to say that call My Symbol MScriptResolver for the symbols existing in the expression.

Example:


 import org.moremotion.evaluator.SymbolResolver;

 public class MySymbolResolver implements org.moremotion.evaluator.SymbolResolver {

   int age = 0;
   boolean retired = false;
   String name = "John Coombes";

   public MySymbolResolver() {
   }

   public double getNumberValue(String symbol) throws Exception {
     if (symbol.equals("AGE")) return age;
     return 0;
   }

   public boolean getBoolValue(String symbol) throws Exception {
     if (symbol.equals("RETIRED")) return retired;
     return false;
   }

   public String getStringValue(String symbol) throws Exception {
     if (symbol.equals("NAME")) return name;
     return "";
   }

   public int getType(String symbol) throws Exception {
     if (symbol.equals("AGE")) return DT_NUMBER;
     if (symbol.equals("RETIRED")) return DT_BOOL;
     return DT_STRING;
   }

   public String getValue(String symbol) throws Exception {
     if (symbol.equals("AGE")) return "" + age;
     if (symbol.equals("RETIRED")) return "" + retired;
     if (symbol.equals("NAME")) return name;
     return "";
   }

   public void setValue(String symbol, String value) throws Exception {
   }

 }
 

Usage Example

 MySymbolResolver msr = new MySymbolResolver();
 Expression expr = new Expression("A + (B / 3) - 2", msr);
 String result = expr.eval();
 

Version:
$Id: SymbolResolver.java 137 2008-05-11 17:24:45Z erkan $

Field Summary
static byte DT_BOOL
           
static byte DT_NULL
           
static byte DT_NUMBER
           
static byte DT_STRING
           
 
Method Summary
 boolean getBoolValue(java.lang.String symbol)
          Returns the value of the given symbol as boolean.
 double getNumberValue(java.lang.String symbol)
          Returns the value of the given symbol as double.
 java.lang.String getStringValue(java.lang.String symbol)
          Returns the value of the given symbol as String.
 int getType(java.lang.String symbol)
          Returns the type of the given symbol.
 java.lang.String getValue(java.lang.String symbol)
          Returns the value of the given symbol as String.
 void setValue(java.lang.String symbol, java.lang.String value)
          Although this method takes place in this interface it will not be called by Expression class.
 

Field Detail

DT_NULL

static final byte DT_NULL
See Also:
Constant Field Values

DT_STRING

static final byte DT_STRING
See Also:
Constant Field Values

DT_NUMBER

static final byte DT_NUMBER
See Also:
Constant Field Values

DT_BOOL

static final byte DT_BOOL
See Also:
Constant Field Values
Method Detail

getType

int getType(java.lang.String symbol)
            throws EvaluationException
Returns the type of the given symbol. The types can be DT_STRING, DT_BOOL or DT_NUMBER

Throws:
EvaluationException

getValue

java.lang.String getValue(java.lang.String symbol)
                          throws EvaluationException
Returns the value of the given symbol as String. This method will be called when type of the symbol is undefined.

Throws:
EvaluationException

getStringValue

java.lang.String getStringValue(java.lang.String symbol)
                                throws EvaluationException
Returns the value of the given symbol as String. This method will be called when type of the symbol is String.

Throws:
EvaluationException

getNumberValue

double getNumberValue(java.lang.String symbol)
                      throws EvaluationException
Returns the value of the given symbol as double. This method will be called when type of the symbol is either int or double.

Throws:
EvaluationException

getBoolValue

boolean getBoolValue(java.lang.String symbol)
                     throws EvaluationException
Returns the value of the given symbol as boolean. This method will be called when type of the symbol is boolean.

Throws:
EvaluationException

setValue

void setValue(java.lang.String symbol,
              java.lang.String value)
              throws EvaluationException
Although this method takes place in this interface it will not be called by Expression class.

Throws:
EvaluationException


Copyright © 2002-2008 MOR YAZILIM. All Rights Reserved.