com.rubecula.jquantity
Class Expression

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--java.util.AbstractList
              |
              +--java.util.Vector
                    |
                    +--com.rubecula.jquantity.Expression
All Implemented Interfaces:
java.lang.Cloneable, java.util.Collection, java.util.List, Presentable, java.util.RandomAccess, Replaceable, java.io.Serializable

public class Expression
extends java.util.Vector
implements Replaceable

Class to manage a mathematical expression. It is the Presentable counterpart to SymbolicPresentation. Elements, the order of which is important, are either of:


Note that although this class is defined in terms of Replaceable (which extends Presentable and java.util.Vector only, nevertheless it uses numerical classes such as BaseNumber and the abstract class of Item. This doesn't seem quite right.

Since:
V_0_3
Version:
$Revision: 1.6 $
Author:
Robin Hillyard
See Also:
Serialized Form

Nested Class Summary
(package private) static class Expression.ExpressionException
          Static class to define an exception encountered when parsing a formula.
 
Nested classes inherited from class java.util.AbstractList
 
Field Summary
 
Fields inherited from class java.util.Vector
capacityIncrement, elementCount, elementData
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
Expression()
          Constructor for an empty formula.
Expression(Presentable presentable)
          Constructor for an "anadic" formula of all strings.
 
Method Summary
 java.lang.String getType()
          This method is primarily for development purposes: it yields the name of the class of the presentable object or, in some cases, the class of the presentable object indirectly referenced.
 Presentable getValue()
          Method to evaluate this expression.
 Presentable getValue(java.lang.Object ignored)
          This method takes this Expression and returns its logical equivalent, i.e.
static void main(java.lang.String[] args)
          Main method for testing this class.
 Presentable makePresentableInstance(Presentation presentation)
          Instance method to convert a Presentation into a Presentable.
static Presentable Parse(Presentation presentation)
          Create a Rational from a Presentation and return it as a Presentable.
static Expression Parse(SymbolicPresentation presentation, java.lang.String identifier)
          Translates the SymbolicPresentation representation of an expression into an instance of Expression.
 Presentation present()
          Convert this Presentable object into a Presentation with default attributes.
 Presentation present(AttrMap attributes)
          Convert this Presentable object into a Presentation, according to the set of attributes provided.
protected static void testExpression(java.io.PrintStream out, SymbolicPresentation sp, java.lang.String label)
           
 
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 java.util.List
iterator, listIterator, listIterator
 

Constructor Detail

Expression

public Expression()
Constructor for an empty formula.


Expression

public Expression(Presentable presentable)
Constructor for an "anadic" formula of all strings.

Parameters:
presentable - the presentable to form this singleton expression.
Method Detail

Parse

public static Expression Parse(SymbolicPresentation presentation,
                               java.lang.String identifier)
                        throws PresentationException
Translates the SymbolicPresentation representation of an expression into an instance of Expression.

Parameters:
presentation - SymbolicPresentation representation to interpret.
identifier - A string with which to identify this Rational.
Returns:
Expression : a new object corresponding to presentation.
Throws:
PresentationException - if the presentation cannot be parsed as an Expression.

getValue

public Presentable getValue()
                     throws PresentableException
Method to evaluate this expression.

Returns:
a Presentable value corresponding to the current value of this expression.
Throws:
PresentableException - name not be found.

getValue

public Presentable getValue(java.lang.Object ignored)
                     throws PresentableException
This method takes this Expression and returns its logical equivalent, i.e. it evaluates the expression. Note that binding is entirely position, and that the implicit operator is times.

Specified by:
getValue in interface Replaceable
Parameters:
ignored - Not used.
Returns:
a Presentable value corresponding to the value of this expression.
Throws:
PresentableException

present

public Presentation present(AttrMap attributes)
                     throws PresentationException
Convert this Presentable object into a Presentation, according to the set of attributes provided.

Specified by:
present in interface Presentable
Parameters:
attributes - a map of desired attributes for this presentation.
Returns:
an appropriate instance of Presentation.
Throws:
PresentationException - if formula cannot be presented with given attributes.

present

public Presentation present()
                     throws PresentationException
Convert this Presentable object into a Presentation with default attributes.

Returns:
an appropriate instance of Presentation.
Throws:
PresentationException - if formula cannot be presented with given attributes.

getType

public java.lang.String getType()
This method is primarily for development purposes: it yields the name of the class of the presentable object or, in some cases, the class of the presentable object indirectly referenced. The text returned is canonical class name (subclasses may choose to override this).

Specified by:
getType in interface Presentable
Returns:
a representation of the effective class of this object.

makePresentableInstance

public Presentable makePresentableInstance(Presentation presentation)
                                    throws PresentationException
Instance method to convert a Presentation into a Presentable. Ideally, this would be a class method, but such a method cannot be defined in an interface. Nor can it be defined in an abstract class with the intention of overriding it in a subclass. Polymorphism just doesn't work that way.
Therefore, the present value (as in fields) of the instance is essentially ignored - only the methods are important.

Specified by:
makePresentableInstance in interface Presentable
Parameters:
presentation - of a number to be converted into a Presentable number.
Returns:
a number in the form of a Presentable.
Throws:
PresentationException - if presentation cannot be parsed appropriately.

Parse

public static Presentable Parse(Presentation presentation)
                         throws PresentationException
Create a Rational from a Presentation and return it as a Presentable.

Parameters:
presentation - A presentation which should be parsed to form a Presentable.
Returns:
A Rational which corresponds to the presentation.
Throws:
PresentationException - if the presentation cannot be parsed as a Presentable object.

testExpression

protected static void testExpression(java.io.PrintStream out,
                                     SymbolicPresentation sp,
                                     java.lang.String label)

main

public static void main(java.lang.String[] args)
Main method for testing this class.

Parameters:
args - String[] : the command line options.