org.ijsberg.iglu.util.logic
Class Expression

java.lang.Object
  extended by org.ijsberg.iglu.util.logic.LogicalElement
      extended by org.ijsberg.iglu.util.logic.Statement
          extended by org.ijsberg.iglu.util.logic.Expression

public class Expression
extends Statement

Logical expression, composed of statements and subexpressions that may be evaluated.

An expression that has been analyzed fully, contains 1 operator and a number of elements that may be evaluated accordingly.


Field Summary
 
Fields inherited from class org.ijsberg.iglu.util.logic.Statement
statement
 
Fields inherited from class org.ijsberg.iglu.util.logic.LogicalElement
AND, NONE, NOT, operatorStr, OR
 
Constructor Summary
Expression(String expression)
          Constructs an expression based on a logical expression defined in a string.
Expression(String expression, boolean useCache)
          Constructs an expression based on a logical expression defined in a string.
 
Method Summary
static void clearCache()
          Clears static expression cache.
static int findEndOfSubExpression(String expression, int start)
          Finds the position of the end bracket ')' matching a start bracket '('.
 int getNrofElements()
           
 String getStatement()
          Performance optimizer: getStatement() in combination with isSingleStatement() isolates a single statement that can be evaluated immediately.
 boolean isSingleStatement()
           
 boolean match(Object[] statements)
          Answers questions like: does "r|w|x" match {"r","x"} (true). does "r|w&x" contain {"r","x"} (true). does "r|w&x" contain {"r"} (true). does "r|w&x" contain {"x"} (false).
 boolean match(String statement)
          Answers questions like: does "r|w|x" match "x" (true). does "r|w&x" match "x" (false).
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Expression

public Expression(String expression)
Constructs an expression based on a logical expression defined in a string. The string may contain

Parameters:
expression -
See Also:
Statement

Expression

public Expression(String expression,
                  boolean useCache)
Constructs an expression based on a logical expression defined in a string. The string may contain

Using the cache is only recommended for expressions that are used as constants

Parameters:
expression -
useCache - expressions will be cached in a static cache if true
See Also:
Statement
Method Detail

findEndOfSubExpression

public static int findEndOfSubExpression(String expression,
                                         int start)
Finds the position of the end bracket ')' matching a start bracket '('.

Parameters:
expression -
start - position of the start bracket
Returns:
position of the matching end bracket or 0 if it can not be located

match

public boolean match(String statement)
Answers questions like:

Parameters:
statement -
Returns:
true if the expression logically matches the statement

match

public boolean match(Object[] statements)
Answers questions like:

Overrides:
match in class Statement
Parameters:
statements -
Returns:
true if the expression logically matches the statement

toString

public String toString()
Overrides:
toString in class Statement
Returns:
a representation of the parsed expression tree

clearCache

public static void clearCache()
Clears static expression cache.


getNrofElements

public int getNrofElements()
Returns:
the number of logical elements this expression contains (not the grand total)

isSingleStatement

public boolean isSingleStatement()
Returns:
true if this expression contains one single statement (is therefor not composed)

getStatement

public String getStatement()
Performance optimizer: getStatement() in combination with isSingleStatement() isolates a single statement that can be evaluated immediately.

Overrides:
getStatement in class Statement
Returns:
the first statement string found


Copyright © 2011. All Rights Reserved.