|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.AbstractCollection java.util.AbstractList java.util.Vector java.util.Stack com.rubecula.jquantity.Mill
This class is responsible for evaluating operations on Presentable objects. It is named in honor of Charles Babbage, father of the (mechanical) computer, and not forgetting the early days of electronic computing, especially in the United Kingdom, and particularly for Maurice Wilkes.
Nested Class Summary |
Nested classes inherited from class java.util.AbstractList |
|
Field Summary | |
private AlphabeticalMap |
_AllOperations
This is the table of all operations. |
private AlphabeticalMap |
_AnadicOperations
This is the table of anadic operations. |
private AlphabeticalMap |
_DyadicOperations
This is the table of dyadic operations. |
private StringMap |
_Memory
The user-definable memory for this mill. |
private AlphabeticalMap |
_MonadicOperations
This is the table of monadic operations. |
private java.lang.String |
_Name
The identifier for this Mill. |
private AlphabeticalMap |
_SpecialOperations
This is the table of special operations. |
protected static StringMap |
CONSTANTS
The system defined (constant) memory for this mill. |
protected static java.lang.String |
K__1
|
protected static java.lang.String |
K_0
|
protected static java.lang.String |
K_1
|
protected static java.lang.String |
K_10
|
protected static java.lang.String |
K_2
|
protected static java.lang.String |
K_3
|
protected static java.lang.String |
K_E
|
protected static java.lang.String |
K_MEM
|
protected static java.lang.String |
K_PI
|
protected static java.lang.String |
OP_2ATAN
|
protected static java.lang.String |
OP_AUDIT
|
protected static java.lang.String |
OP_CHS
|
protected static java.lang.String |
OP_COPY
|
protected static java.lang.String |
OP_DIFFERENCE
|
protected static java.lang.String |
OP_E
|
protected static java.lang.String |
OP_EXP
|
protected static java.lang.String |
OP_INV
|
protected static java.lang.String |
OP_LOG
|
protected static java.lang.String |
OP_NOOP
|
protected static java.lang.String |
OP_PI
|
protected static java.lang.String |
OP_POWER
|
protected static java.lang.String |
OP_PRODUCT
|
protected static java.lang.String |
OP_QUOTIENT
|
protected static java.lang.String |
OP_SUM
|
protected static java.lang.String |
OP_SWAP
|
protected static java.lang.String |
OP_TANHALF
|
Fields inherited from class java.util.Stack |
|
Fields inherited from class java.util.Vector |
capacityIncrement, elementCount, elementData |
Fields inherited from class java.util.AbstractList |
modCount |
Constructor Summary | |
Mill(java.lang.String name)
Principal constructor for a new Mill. |
Method Summary | |
protected void |
addConstant(java.lang.String key,
Presentable value)
MUTATING method to add a constant. |
void |
addConstants(Lookupable table)
MUTATING method to add a table of constants. |
java.lang.String |
audit()
Method to return a detailed (unlabeled) string from an object for debugging purposes. |
void |
audit(java.io.PrintStream out,
java.lang.String label)
Method to output detailed string from an object for debugging purposes. |
java.lang.String |
audit(java.lang.String label)
Method to return a detailed string from an object for debugging purposes. |
private static BaseNumber |
BaseNumberProduct(BaseNumber operand1,
BaseNumber operand2)
Static method to get the product of two BaseNumbers. |
private static Millable |
ChangeSign(Millable operand)
|
private static Millable |
EvaluatePower(int power,
BaseNumber number)
|
int |
getAdy(java.lang.String operator)
This method returns the number of presentables needed to popped off the stack for an operation. |
java.lang.String |
getIdentifier()
Method to get the specific identifier for an object. |
java.util.Collection |
getKeys()
Method to get the keyset for this Mill's constants. |
AlphabeticalMap |
getOperations()
Method to get a map which represents the supported functions of this Mill. |
Presentable |
getValue(java.lang.String key)
Method to get a memory presentable defined by key. |
void |
help(java.io.PrintStream output)
This method outputs help information listing and describing the various operations supported by the mill. |
private void |
initOperations()
|
private static Millable |
Invert(int power,
BaseNumber number)
|
private boolean |
IsDyadic(java.lang.String operator)
|
private static boolean |
IsTrig(java.lang.String operator)
|
java.lang.String |
lookupOperator(java.lang.String description)
This method returns the name of an operator whose description matches the string description in some way. |
static void |
main(java.lang.String[] args)
Main method for testing this class. |
void |
operate(java.lang.String operator)
Mutating method to apply the operation operator to the stack. |
private void |
operate(java.lang.String operator,
Millable top)
Mutating method to apply a dyadic operation operator to the stack. |
private java.lang.Object |
operateDyadic(java.lang.String operator,
Millable next,
Millable top)
|
private Millable |
popNumber()
This method takes a Presentable object and returns the corresponding BaseNumber. |
private static Millable |
Pow(Millable operand,
int power)
|
private static Millable |
Product(Millable operand1,
Millable operand2)
Private Method to implement multiplication of operands in the mill. |
void |
push(Presentable operand)
Mutating method to push operand onto the top of the Mill stack. |
void |
setValue(java.lang.String key,
Presentable value)
Method to set a value which can later be retrieved using the name given (using the method defined by the Lookupable interface). |
private static Millable |
Sum(Millable operand1,
Millable operand2)
|
Methods inherited from class java.util.Stack |
empty, peek, pop, push, search |
Methods inherited from class java.util.Vector |
add, add, addAll, addAll, addElement, capacity, clear, clone, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, equals, firstElement, get, hashCode, indexOf, indexOf, insertElementAt, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, remove, removeAll, removeAllElements, removeElement, removeElementAt, removeRange, retainAll, set, setElementAt, setSize, size, subList, toArray, toArray, toString, trimToSize |
Methods inherited from class java.util.AbstractList |
iterator, listIterator, listIterator |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.rubecula.util.MillInterface |
pop, size |
Methods inherited from interface java.util.List |
iterator, listIterator, listIterator |
Field Detail |
private final AlphabeticalMap _AllOperations
private final AlphabeticalMap _DyadicOperations
private final AlphabeticalMap _MonadicOperations
private final AlphabeticalMap _AnadicOperations
private final AlphabeticalMap _SpecialOperations
private final java.lang.String _Name
private final StringMap _Memory
protected static final StringMap CONSTANTS
protected static final java.lang.String OP_SUM
protected static final java.lang.String OP_DIFFERENCE
protected static final java.lang.String OP_PRODUCT
protected static final java.lang.String OP_QUOTIENT
protected static final java.lang.String OP_POWER
protected static final java.lang.String OP_2ATAN
protected static final java.lang.String OP_TANHALF
protected static final java.lang.String OP_EXP
protected static final java.lang.String OP_LOG
protected static final java.lang.String OP_CHS
protected static final java.lang.String OP_INV
protected static final java.lang.String OP_PI
protected static final java.lang.String OP_E
protected static final java.lang.String OP_COPY
protected static final java.lang.String OP_AUDIT
protected static final java.lang.String OP_SWAP
protected static final java.lang.String OP_NOOP
protected static final java.lang.String K_PI
protected static final java.lang.String K_E
protected static final java.lang.String K__1
protected static final java.lang.String K_0
protected static final java.lang.String K_1
protected static final java.lang.String K_2
protected static final java.lang.String K_3
protected static final java.lang.String K_10
protected static final java.lang.String K_MEM
Constructor Detail |
public Mill(java.lang.String name)
name
- by which this Mill will be referred to.Method Detail |
public void push(Presentable operand) throws MillException
push
in interface MillInterface
operand
- a presentable object which will displace the former top
of the stack to the second position and itself become the top object.
MillException
- operand not a BaseNumber.public void operate(java.lang.String operator) throws java.util.EmptyStackException, MillException
Mutating method to apply the operation operator to the stack. The number of items required on the stack prior to the operation and the number of items left on the stack afterwards depends upon the operation.
operate
in interface MillInterface
operator
- the name for the operation.
The following operators ONLY are supported by this Mill:
java.util.EmptyStackException
MillException
public Presentable getValue(java.lang.String key)
getValue
in interface Lookupable
key
- the name of the memory object, without any preceding "$".
public void setValue(java.lang.String key, Presentable value) throws MillException
setValue
in interface MillInterface
key
- the name or key by which this value can be retrieved
(without any preceding "$").value
- a Presentable value which is lookupable.
MillException
- if memory slot name cannot be set to value,
because the name is already in use (or an attempt to remove a constant).
// TODO Why isn't this method defined in Lookupable?public AlphabeticalMap getOperations()
getOperations
in interface MillInterface
public java.lang.String lookupOperator(java.lang.String description) throws MillException
lookupOperator
in interface MillInterface
description
- the mathematical name or description of the operator.
MillException
- more than one operator matched.public void help(java.io.PrintStream output)
help
in interface MillInterface
output
- an output stream.
// TODO sort by key.public java.lang.String getIdentifier()
getIdentifier
in interface Identifiable
public java.lang.String audit(java.lang.String label)
audit
in interface Auditable
label
- the label to associate with the data.
If label is non-null, a more detailed audit will be returned (this
normally occurs only at the top level).
public java.lang.String audit()
audit
in interface Auditable
public void audit(java.io.PrintStream out, java.lang.String label)
audit
in interface Auditable
out
- the output stream.label
- the label to attach to the output (may be null).private void operate(java.lang.String operator, Millable top) throws java.util.EmptyStackException, MillException
operator
- the name for the operation. Different Mills will naturally
support different operations.top
- the value which was on the top of the stack (or null).
java.util.EmptyStackException
MillException
private boolean IsDyadic(java.lang.String operator)
private static boolean IsTrig(java.lang.String operator)
private java.lang.Object operateDyadic(java.lang.String operator, Millable next, Millable top) throws InvalidOperandException, MillException
InvalidOperandException
MillException
private Millable popNumber() throws MillException
MillException
- if top of stack is not a BaseNumber.public int getAdy(java.lang.String operator) throws MillException
getAdy
in interface MillInterface
operator
- the name (abbreviation) of the operator.
MillException
- operator is not supported.public void addConstants(Lookupable table)
addConstants
in interface MillInterface
table
- the set of constants to be added.protected void addConstant(java.lang.String key, Presentable value)
key
- the constant's key for retrieval purposes.value
- the constant's value.private static Millable ChangeSign(Millable operand) throws MillException
MillException
private static Millable Pow(Millable operand, int power) throws MillException
MillException
private static Millable EvaluatePower(int power, BaseNumber number)
private static Millable Invert(int power, BaseNumber number) throws MillException
MillException
private static Millable Sum(Millable operand1, Millable operand2) throws MillException, InvalidOperandException
MillException
InvalidOperandException
private static Millable Product(Millable operand1, Millable operand2) throws MillException, InvalidOperandException
operand1
- a Millable objectoperand2
- a Millable object
MillException
- a problem which could not be worked around
InvalidOperandException
- this should point to a programming error:
there should be no combination of Millable operands which cannot by multiplied
together.private static BaseNumber BaseNumberProduct(BaseNumber operand1, BaseNumber operand2) throws InvalidOperandException
operand1
- operand2
-
InvalidOperandException
private void initOperations()
public static void main(java.lang.String[] args)
args
- String[] : the command line options.public java.util.Collection getKeys()
getKeys
in interface Lookupable
Lookupable.getKeys()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |