Top Inners Fields Constructors Methods
org.hsqldb.cmdline.sqltool

public Class Calculator

extends Object
Class Inheritance
Imports
java.util.List, .ArrayList, .Map, .HashMap, .EnumSet, java.util.regex.Pattern

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private static enum

Field Summary

Modifier and TypeField and Description
private List<Calculator.Atom>
private static Pattern
private EnumSet<Calculator.MathOp>
private Map<String, String>

Constructor Summary

AccessConstructor and Description
public
public
Calculator(String s, Map<String, String> vars)

Every integer, var name, and single-math-op-character get their own tokens here.

Method Summary

Modifier and TypeMethod and Description
private long
deref(String varName)

public static void
main(String[] sa)

public static long
reassignValue(String assignee, Map<String, String> valMap, String opStr, String expr)

Does not actually do the assigment, but validates the input variable and returns the value ready to be assigned to it.

public long

Returns:

Value that all visited atoms reduce to.
reduce
(int startAtomIndex, boolean stopAtParenClose)

If atoms[startAtomIndex] == '(', then last visited atoms will be the next top-level (un-paired) ')'.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

atomsback to summary
private List<Calculator.Atom> atoms
intPatternback to summary
private static Pattern intPattern
TradOrLParenback to summary
private EnumSet<Calculator.MathOp> TradOrLParen
varsback to summary
private Map<String, String> vars

Constructor Detail

Calculatorback to summary
public Calculator(String[] sa, Map<String, String> vars)
Calculatorback to summary
public Calculator(String s, Map<String, String> vars)

Every integer, var name, and single-math-op-character get their own tokens here. Special processesing is needed afterwards because negative signs get separated into separate tokens.

Method Detail

derefback to summary
private long deref(String varName)
mainback to summary
public static void main(String[] sa)
reassignValueback to summary
public static long reassignValue(String assignee, Map<String, String> valMap, String opStr, String expr)

Does not actually do the assigment, but validates the input variable and returns the value ready to be assigned to it.

reduceback to summary
public long reduce(int startAtomIndex, boolean stopAtParenClose)

If atoms[startAtomIndex] == '(', then last visited atoms will be the next top-level (un-paired) ')'. Otherwise, all remainign atoms will be visited. Every visited atom will be removed from 'atoms'.

Returns:long

Value that all visited atoms reduce to.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

org.hsqldb.cmdline.sqltool back to summary

private Class Calculator.Atom

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
public Calculator.MathOp
public long

Constructor Summary

AccessConstructor and Description
private
Atom(String token)

private
private
Atom(long val)

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

opback to summary
public Calculator.MathOp op
valback to summary
public long val

Constructor Detail

Atomback to summary
private Atom(String token)
Atomback to summary
private Atom(Calculator.MathOp op)
Atomback to summary
private Atom(long val)

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

org.hsqldb.cmdline.sqltool back to summary

private final Enum Calculator.MathOp

extends Enum<Calculator.MathOp>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final Calculator.MathOp
private char
c

public static final Calculator.MathOp
public static final Calculator.MathOp
public static final Calculator.MathOp
public static final Calculator.MathOp
public static final Calculator.MathOp
public static final Calculator.MathOp
public static final Calculator.MathOp

Constructor Summary

AccessConstructor and Description
private
MathOp(char c)

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration.

public static Calculator.MathOp
public static Calculator.MathOp
valueOf(char c)

public static Calculator.MathOp[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinalvalueOf

Field Detail

ADDback to summary
public static final Calculator.MathOp ADD
cback to summary
private char c
DIVIDEback to summary
public static final Calculator.MathOp DIVIDE
LPARENback to summary
public static final Calculator.MathOp LPAREN
MULTIPLYback to summary
public static final Calculator.MathOp MULTIPLY
POWERback to summary
public static final Calculator.MathOp POWER
REMback to summary
public static final Calculator.MathOp REM
RPARENback to summary
public static final Calculator.MathOp RPAREN
SUBTRACTback to summary
public static final Calculator.MathOp SUBTRACT

Constructor Detail

MathOpback to summary
private MathOp(char c)

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Enum.toString.

Doc from java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration. This method may be overridden, though it typically isn't necessary or desirable. An enum class should override this method when a more "programmer-friendly" string form exists.

valueOfback to summary
public static Calculator.MathOp valueOf(String name)
valueOfback to summary
public static Calculator.MathOp valueOf(char c)
valuesback to summary
public static Calculator.MathOp[] values()