infix2postfix
Class MathClient

java.lang.Object
  extended byinfix2postfix.Infix2PostfixClient
      extended byinfix2postfix.MathClient

public class MathClient
extends Infix2PostfixClient

This class represents client interface for Infix to postfix conversion and postfix evaluation for mathematical expressions.
This math client supports operators like,

 1. +
 2. -
 3. unary -
 4. *
 5. /
 6. max (function operator)
 

This math client supports following basic data types to provide more control over results and operand value ranges,
 1. int
 2. long
 3. float
 4. double
 

In addition, this client supports various radix systems defined in range- Character.MIN_RADIX and Character.MAX_RADIX.

Author:
maulin

Nested Class Summary
static class MathClient.OperandManagers
          Operand Manager's Enumeration.
 
Field Summary
private static NumericOperandManager defaultOperandManager
          Default operand manager for this math client
static java.lang.Object NULL_OPERAND
          DUMMY operand for this client used in unary operator calculations
 
Fields inherited from class infix2postfix.Infix2PostfixClient
operandManager
 
Constructor Summary
MathClient()
          No-arg constructor.
MathClient(NumericOperandManager operandManager)
          Constructs this object with given type of numeric operand manager.
 
Method Summary
protected  void addDefaultOperators()
          Adds default supported operators to the "valid operators" list.
 java.lang.String convertForRadix(double result)
          Converts double result to specific radix for the associated operand manager with this client.
 java.lang.String convertForRadix(float result)
          Converts float result to specific radix for the associated operand manager with this client.
 java.lang.String convertForRadix(int result)
          Converts int result to specific radix for the associated operand manager with this client.
 java.lang.String convertForRadix(long result)
          Converts long result to specific radix for the associated operand manager with this client.
protected static NumericOperandManager getDefaultOperandManager()
          Returns default numeric operand manager.
 double getDoubleOperand(java.lang.Object operand)
          Returns operand in double format.
 float getFloatOperand(java.lang.Object operand)
          Returns operand in float format.
 int getIntegerOperand(java.lang.Object operand)
          Returns operand in int format.
 long getLongOperand(java.lang.Object operand)
          Returns operand in long format.
 int getRadix()
          Returns the radix for the numeric operands associated with this client.
 void setRadix(int radix)
          Sets the radix for the numeric operands.
 
Methods inherited from class infix2postfix.Infix2PostfixClient
addOperator, evaluate, getDefaultVariableHolder, getOperandManager, getVariableValue, removeOperator, setVariable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NULL_OPERAND

public static final java.lang.Object NULL_OPERAND
DUMMY operand for this client used in unary operator calculations


defaultOperandManager

private static NumericOperandManager defaultOperandManager
Default operand manager for this math client

Constructor Detail

MathClient

public MathClient()
No-arg constructor. It uses default operand manager returned by getDefaultOperandManager method.

See Also:
getDefaultOperandManager()

MathClient

public MathClient(NumericOperandManager operandManager)
Constructs this object with given type of numeric operand manager.

Method Detail

getDefaultOperandManager

protected static NumericOperandManager getDefaultOperandManager()
Returns default numeric operand manager. Default numeric operand manager is OperandManagers#DOUBLE_OP_MANAGER

See Also:
MathClient.OperandManagers.DOUBLE_OP_MANAGER

convertForRadix

public java.lang.String convertForRadix(int result)
Converts int result to specific radix for the associated operand manager with this client.

See Also:
IntegerOperandManager.convertForRadix(int)

getIntegerOperand

public int getIntegerOperand(java.lang.Object operand)
                      throws InvalidOperandException
Returns operand in int format.

Throws:
InvalidOperandException
See Also:
IntegerOperandManager.getIntegerOperand(Object)

convertForRadix

public java.lang.String convertForRadix(long result)
Converts long result to specific radix for the associated operand manager with this client.

See Also:
LongOperandManager.convertForRadix(long)

getLongOperand

public long getLongOperand(java.lang.Object operand)
                    throws InvalidOperandException
Returns operand in long format.

Throws:
InvalidOperandException
See Also:
LongOperandManager.getLongOperand(Object)

convertForRadix

public java.lang.String convertForRadix(float result)
Converts float result to specific radix for the associated operand manager with this client.

See Also:
FloatOperandManager.convertForRadix(float)

getFloatOperand

public float getFloatOperand(java.lang.Object operand)
                      throws InvalidOperandException
Returns operand in float format.

Throws:
InvalidOperandException
See Also:
FloatOperandManager.getFloatOperand(Object)

convertForRadix

public java.lang.String convertForRadix(double result)
Converts double result to specific radix for the associated operand manager with this client.

See Also:
DoubleOperandManager.convertForRadix(double)

getDoubleOperand

public double getDoubleOperand(java.lang.Object operand)
                        throws InvalidOperandException
Returns operand in double format.

Throws:
InvalidOperandException
See Also:
DoubleOperandManager.getDoubleOperand(Object)

addDefaultOperators

protected void addDefaultOperators()
Adds default supported operators to the "valid operators" list.
Default operators are, +, - , unary -, *, /.

Specified by:
addDefaultOperators in class Infix2PostfixClient
See Also:
addDefaultOperators(), BooleanClient.addDefaultOperators()

setRadix

public void setRadix(int radix)
Sets the radix for the numeric operands.

See Also:
NumericOperandManager.setRadix(int)

getRadix

public int getRadix()
Returns the radix for the numeric operands associated with this client.

See Also:
NumericOperandManager.getRadix()