vec_math
Class BooleanParser

java.lang.Object
  extended by vec_math.BooleanParser

public class BooleanParser
extends Object

A class providing arithmetics for booleans. Operators used are (sorted for precedence):

Only two values of the operands are allowed, true and false. If a string obeying the above rules is passed to the class's #valueOf method, it is parsed and the reslut, true or false is returned. Parsing errors result in a ParseException to be thrown. Please note that a ParseException is not a runtime exception, therefore it must be caught in calling routines.


Nested Class Summary
static class BooleanParser.Test
          Mainly test purpose.
 
Field Summary
private static List<Operator<String>> valid
          All valid operators.
 
Constructor Summary
BooleanParser()
           
 
Method Summary
static Boolean evaluateBoolean(String expression)
          Parses the node and returns the expression as a Boolean object.
private static String evaluateNode(Node<String> root)
          Evaluates a node.
private static String evaluateSingle(Operator<String> tie, String left, String right)
          Evaluates a single boolean expression.
protected static List<Operator<String>> getValid()
          Returns all valid operator in this parsers context.
static String parseBoolean(String expression)
          Parses the given string to obtain a single boolean value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

valid

private static final List<Operator<String>> valid
All valid operators.

Constructor Detail

BooleanParser

public BooleanParser()
Method Detail

parseBoolean

public static String parseBoolean(String expression)
                           throws ParseException
Parses the given string to obtain a single boolean value. Note that no variables are allowed within the String. Presedence of the operators follows JAVA standard rules and can be altered with parentheses.

Parameters:
expression - A String combining boolean constants
Throws:
ParseException - If the argument does not obey the specified grammar.

evaluateBoolean

public static Boolean evaluateBoolean(String expression)
                               throws ParseException
Parses the node and returns the expression as a Boolean object.

Throws:
ParseException

getValid

protected static List<Operator<String>> getValid()
Returns all valid operator in this parsers context.


evaluateNode

private static String evaluateNode(Node<String> root)
                            throws ParseException
Evaluates a node. Branches recursevely into sub-nodes until all dependencies are removed.

Throws:
ParseException

evaluateSingle

private static String evaluateSingle(Operator<String> tie,
                                     String left,
                                     String right)
                              throws ParseException
Evaluates a single boolean expression. Care must be taken to obtain a match in this routine with the static initializer.

Throws:
ParseException