net.sourceforge.jeval.operator
Class AbstractOperator

java.lang.Object
  extended by net.sourceforge.jeval.operator.AbstractOperator
All Implemented Interfaces:
Operator
Direct Known Subclasses:
AdditionOperator, BooleanAndOperator, BooleanNotOperator, BooleanOrOperator, ClosedParenthesesOperator, DivisionOperator, EqualOperator, GreaterThanOperator, GreaterThanOrEqualOperator, LessThanOperator, LessThanOrEqualOperator, ModulusOperator, MultiplicationOperator, NotEqualOperator, OpenParenthesesOperator, SubtractionOperator

public abstract class AbstractOperator
extends java.lang.Object
implements Operator

This is the standard operator that is the parent to all operators found in expressions.


Constructor Summary
AbstractOperator(java.lang.String symbol, int precedence)
          A constructor that takes the operator symbol and precedence as input.
AbstractOperator(java.lang.String symbol, int precedence, boolean unary)
          A constructor that takes the operator symbol, precedence, unary indicator and unary precedence as input.
 
Method Summary
 boolean equals(java.lang.Object object)
          Determines if this operator is equal to another operator.
 double evaluate(double operand)
          Evaluate one double operand.
 double evaluate(double leftOperand, double rightOperand)
          Evaluates two double operands.
 java.lang.String evaluate(java.lang.String leftOperand, java.lang.String rightOperand)
          Evaluates two string operands.
 int getLength()
          Returns the length of the operator symbol.
 int getPrecedence()
          Returns the precedence given to this operator.
 java.lang.String getSymbol()
          Returns the character(s) that makes up the operator.
 boolean isUnary()
          Returns an indicator of if the operator is unary or not.
 java.lang.String toString()
          Returns the String representation of this operator, which is the symbol.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractOperator

public AbstractOperator(java.lang.String symbol,
                        int precedence)
A constructor that takes the operator symbol and precedence as input.

Parameters:
symbol - The character(s) that makes up the operator.
precedence - The precedence level given to this operator.

AbstractOperator

public AbstractOperator(java.lang.String symbol,
                        int precedence,
                        boolean unary)
A constructor that takes the operator symbol, precedence, unary indicator and unary precedence as input.

Parameters:
symbol - The character(s) that makes up the operator.
precedence - The precedence level given to this operator.
unary - Indicates of the operator is a unary operator or not.
Method Detail

evaluate

public double evaluate(double leftOperand,
                       double rightOperand)
Evaluates two double operands.

Specified by:
evaluate in interface Operator
Parameters:
leftOperand - The left operand being evaluated.
rightOperand - The right operand being evaluated.

evaluate

public java.lang.String evaluate(java.lang.String leftOperand,
                                 java.lang.String rightOperand)
                          throws EvaluationException
Evaluates two string operands.

Specified by:
evaluate in interface Operator
Parameters:
leftOperand - The left operand being evaluated.
rightOperand - The right operand being evaluated.
Returns:
String The value of the evaluated operands.
Throws:
EvaluateException - Thrown when an error is found while evaluating the expression.
EvaluationException

evaluate

public double evaluate(double operand)
Evaluate one double operand.

Specified by:
evaluate in interface Operator
Parameters:
operand - The operand being evaluated.

getSymbol

public java.lang.String getSymbol()
Returns the character(s) that makes up the operator.

Specified by:
getSymbol in interface Operator
Returns:
The operator symbol.

getPrecedence

public int getPrecedence()
Returns the precedence given to this operator.

Specified by:
getPrecedence in interface Operator
Returns:
The precedecne given to this operator.

getLength

public int getLength()
Returns the length of the operator symbol.

Specified by:
getLength in interface Operator
Returns:
The length of the operator symbol.

isUnary

public boolean isUnary()
Returns an indicator of if the operator is unary or not.

Specified by:
isUnary in interface Operator
Returns:
An indicator of if the operator is unary or not.

equals

public boolean equals(java.lang.Object object)
Determines if this operator is equal to another operator. Equality is determined by comparing the operator symbol of both operators.

Overrides:
equals in class java.lang.Object
Parameters:
object - The object to compare with this operator.
Returns:
True if the object is equal and false if not.
Throws:
java.lang.IllegalStateException - Thrown if the input object is not of the Operator type.

toString

public java.lang.String toString()
Returns the String representation of this operator, which is the symbol.

Overrides:
toString in class java.lang.Object
Returns:
The operator symbol.


Copyright (C) 2002-2007 Robert Breidecker.