com.rubecula.spreadsheet
Class Formula

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

public class Formula
extends java.util.Vector
implements Presentable

Class to manage a list of elements, starting with the operator and continuing with the operands in order. The operands may be in any of three forms:


Formulas can be of any length, but normally consist of up to 3 elements.

Version:
$Revision: 1.4 $
Author:
Robin Hillyard
See Also:
Serialized Form

Nested Class Summary
(package private) static class Formula.FormulaException
          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
Formula(java.lang.String operator)
          Constructor for an "anadic" formula of all strings.
Formula(java.lang.String operator, java.lang.Object operand)
          Constructor for a "monadic" formula of all strings.
Formula(java.lang.String operator, java.lang.Object operand1, java.lang.Object operand2)
          Constructor for a "dyadic" formula of all strings.
 
Method Summary
 void dereference(Presentable dependent, CellTable cells)
          Method to dereference a formula and at the same time, set up dependencies.
 Presentable evaluate()
          Convert this Presentable object into a Presentation.
 Presentable getElement()
          MUTATING method to get the first element from the formula as a Presentable.
 Presentable makePresentableInstance(Presentation x)
          Instance method to convert a Presentation into a Presentable.
 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.
static Formula valueOf(java.lang.String formula)
          Factory method to yield a Formula from a string.
 
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

Formula

public Formula(java.lang.String operator)
Constructor for an "anadic" formula of all strings.

Parameters:
operator - the operator.

Formula

public Formula(java.lang.String operator,
               java.lang.Object operand)
Constructor for a "monadic" formula of all strings.

Parameters:
operator - the operator.
operand - the operand.

Formula

public Formula(java.lang.String operator,
               java.lang.Object operand1,
               java.lang.Object operand2)
Constructor for a "dyadic" formula of all strings.

Parameters:
operator - the operator.
operand1 - the first operand.
operand2 - the second operand.
Method Detail

valueOf

public static Formula valueOf(java.lang.String formula)
                       throws Formula.FormulaException
Factory method to yield a Formula from a string.

Parameters:
formula - the required formula in string form.
Returns:
a Formula derived from the string formula.
Throws:
Formula.FormulaException
Formula.FormulaException

evaluate

public Presentable evaluate()
                     throws PresentableException
Convert this Presentable object into a Presentation.

Returns:
an appropriate instance of Presentable OR null (if a reference is not available).
Throws:
PresentableException
SpreadsheetException

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.

makePresentableInstance

public Presentable makePresentableInstance(Presentation x)
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:
x - a presentation of a number which you want to convert into a number.
Returns:
a number in the form of a Presentable.

dereference

public void dereference(Presentable dependent,
                        CellTable cells)
Method to dereference a formula and at the same time, set up dependencies.

Parameters:
dependent - the presentable (a QuantityCell) which is dependent on this formula.
cells - map of relevant cells.

getElement

public Presentable getElement()
                       throws PresentableException
MUTATING method to get the first element from the formula as a Presentable.
Note that the element is removed from the formula as a result of calling this method!

Returns:
the first element, which is removed from the list.
Throws:
PresentableException