csheets.ext.assertion
Class AssertableCell

java.lang.Object
  extended by csheets.ext.CellExtension
      extended by csheets.ext.assertion.AssertableCell
All Implemented Interfaces:
Cell, CellListener, Extensible<Cell>, Serializable, Comparable<Cell>, EventListener

public class AssertableCell
extends CellExtension

An extension of a cell in a spreadsheet, with support for assertions.

Author:
Peter Palotas, Fredrik Johansson, Einar Pehrson
See Also:
Serialized Form

Constructor Summary
AssertableCell(Cell cell)
          Creates a assertable cell extension for the given cell.
 
Method Summary
 void addAssertableCellListener(AssertableCellListener listener)
          Registers the given listener on the cell.
 Assertion.Result assertAny()
          Asserts the current value of the cell using any (or both) assertion(s) associated with the cell.
 Assertion.Result assertAny(Value value)
          Asserts the specified value using any (or both) assertion(s) associated with the cell.
 Assertion.ComparisonResult assertAssertions()
          Checks wether the assertions associated with the cell agree with each other and that no division by zero can occur using values within this assertion.
 Assertion.Result assertSG()
          Asserts the current value of the cell using the system generated assertion associated with the cell.
 Assertion.Result assertSG(Value value)
          Asserts the specified value using the system generated assertion associated with the cell.
 Assertion.Result assertUS()
          Asserts the current value of the cell using the user supplied assertion associated with the cell.
 Assertion.Result assertUS(Value value)
          Asserts the specified value using the user supplied assertion associated with the cell.
 void contentChanged(Cell cell)
          Invoked when the content of a cell has been changed.
protected  void fireAssertionsChanged()
          Notifies all registered listeners that the cell's assertions changed.
 void generateAssertion()
          Invoked to indicate that the content of the cell in the spreadsheet was modified and that assertions that depend on that data must be updated.
 Assertion getPriorityAssertion()
          Get the most significant assertion of the cell.
 SGAssertion getSGAssertion()
          Get the cell's system generated assertion.
 USAssertion getUSAssertion()
          Get the cell's user supplied assertion.
 boolean hasAssertionError()
          Checks wether there are any errors or inconsitencies in the cell related to assertions.
 boolean isAsserted()
          Returns whether the cell has an assertion.
 boolean isSGAsserted()
          Checks if the cell has a system generated assertion associated with it.
 boolean isUSAsserted()
          Checks if the cell has a user supplied assertion associated with it.
 void removeAssertableCellListener(AssertableCellListener listener)
          Removes the given listener from the cell.
 void setUSAssertion(USAssertion assertion)
          Sets the user-specified assertion for the cell.
 
Methods inherited from class csheets.ext.CellExtension
addCellListener, cellCleared, cellCopied, clear, compareTo, copyFrom, dependentsChanged, getAddress, getCellListeners, getContent, getDelegate, getDependents, getExtension, getFormula, getName, getPrecedents, getSpreadsheet, getValue, moveFrom, removeCellListener, setContent, toString, valueChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AssertableCell

AssertableCell(Cell cell)
Creates a assertable cell extension for the given cell.

Parameters:
cell - the cell to extend
Method Detail

contentChanged

public void contentChanged(Cell cell)
Description copied from interface: CellListener
Invoked when the content of a cell has been changed. As a consequence, the cell's formula and its precedents may have changed.

Specified by:
contentChanged in interface CellListener
Overrides:
contentChanged in class CellExtension
Parameters:
cell - the cell that was modified

getUSAssertion

public USAssertion getUSAssertion()
Get the cell's user supplied assertion.

Returns:
The user supplied assertion for the cell or null if no user supplied assertion exists.

getSGAssertion

public SGAssertion getSGAssertion()
Get the cell's system generated assertion.

Returns:
The system generated assertion for the cell or null if no system generated assertion exist.

getPriorityAssertion

public Assertion getPriorityAssertion()
Get the most significant assertion of the cell. This is currently the System Generated Assertion if one exists, and the user supplied assertion otherwise.

Returns:
the most significant assertion if one exists, or null otherwise.

isAsserted

public boolean isAsserted()
Returns whether the cell has an assertion.

Returns:
true if the cell has an assertion

isUSAsserted

public boolean isUSAsserted()
Checks if the cell has a user supplied assertion associated with it.

Returns:
true if the cell has a user supplied assertion associated with it, false otherwise.

isSGAsserted

public boolean isSGAsserted()
Checks if the cell has a system generated assertion associated with it.

Returns:
true if the cell has a system generated assertion associated with it, false otherwise.

setUSAssertion

public void setUSAssertion(USAssertion assertion)
Sets the user-specified assertion for the cell.

Parameters:
assertion - the user-specified assertion

generateAssertion

public void generateAssertion()
Invoked to indicate that the content of the cell in the spreadsheet was modified and that assertions that depend on that data must be updated.


assertUS

public Assertion.Result assertUS()
Asserts the current value of the cell using the user supplied assertion associated with the cell.

Returns:
the result of the assertion. If no assertion exists, Assertion.Result.OK is returned.
See Also:
Assertion.validate(Value)

assertUS

public Assertion.Result assertUS(Value value)
Asserts the specified value using the user supplied assertion associated with the cell.

Returns:
the result of the assertion. If no assertion exists, Assertion.Result.OK is returned.
See Also:
Assertion.validate(Value)

assertSG

public Assertion.Result assertSG()
Asserts the current value of the cell using the system generated assertion associated with the cell.

Returns:
the result of the assertion. If no assertion exists, Assertion.Result.OK is returned.
See Also:
Assertion.validate(Value)

assertSG

public Assertion.Result assertSG(Value value)
Asserts the specified value using the system generated assertion associated with the cell.

Returns:
the result of the assertion. If no assertion exists, Assertion.Result.OK is returned.
See Also:
Assertion.validate(Value)

assertAny

public Assertion.Result assertAny(Value value)
Asserts the specified value using any (or both) assertion(s) associated with the cell. The system generated assertion (if available) will be run first and upon error its return code will be returned. If the value was successfully asserted using the system generated assertion then the value will be asserted using the user supplied assertion, and its return code will be returned. If no assertion is available in the cell Assertion.Result.OK will be returned.

Returns:
the success status of the assertion.
See Also:
Assertion.validate(Value)

assertAny

public Assertion.Result assertAny()
Asserts the current value of the cell using any (or both) assertion(s) associated with the cell. The system generated assertion (if available) will be run first and upon error its return code will be returned. If the value was successfully asserted using the system generated assertion then the value will be asserted using the user supplied assertion, and its return code will be returned. If no assertion is available in the cell Assertion.Result.OK will be returned.

Returns:
the success status of the assertion.
See Also:
Assertion.validate(Value)

assertAssertions

public Assertion.ComparisonResult assertAssertions()
Checks wether the assertions associated with the cell agree with each other and that no division by zero can occur using values within this assertion.

Returns:
  • Assertion.ComparisonResult.OK if both the SGA and USA are specified for the cell and are equal or if none or only one of them is specified, AND the system generated assertion did not fail to generate because it would include a division by zero error.
  • Assertion.ComparisonResult.NON_EQUAL if the SGA and USA are both specified and do not agree with each other.
  • Assertion.ComparisonResult.DIV_BY_ZERO if the SGA failed to be generated because it would lead to a division by zero error, either because of errenous assertions in precedents or an errenous formula in the cell.

hasAssertionError

public boolean hasAssertionError()
Checks wether there are any errors or inconsitencies in the cell related to assertions.

Returns:
false if there are no errors that can be found in the cell using assertion related functions, true otherwise.

addAssertableCellListener

public void addAssertableCellListener(AssertableCellListener listener)
Registers the given listener on the cell.

Parameters:
listener - the listener to be added

removeAssertableCellListener

public void removeAssertableCellListener(AssertableCellListener listener)
Removes the given listener from the cell.

Parameters:
listener - the listener to be removed

fireAssertionsChanged

protected void fireAssertionsChanged()
Notifies all registered listeners that the cell's assertions changed.