Using Bean Sheet Commands

Bean Sheet defines a number of Bean Shell-style commands. Other commands can be defined as per Bean Shell specification. All commands described below adhere to the following rules:

avg

double avg(Iterator range)

Returns a numerical average of cell values in the range provided.

condition

Iterator condition(Iterator iterator, String expression)

Returns an iterator that iterates through a subset of elements returned by iterator based on evaluation of expression for each element. At the time of evaluation of this expression, a variable is put into the namespace under the key val whose value is the element being tested. If the result of expression evaluation is boolean or Boolean and is true, the element being tested is returned by the resulting iterator. A typical use of this command is for defining subranges based on certain filtering conditions. In such a context, val denotes the coordinate of a cell, rather than its value and so deref should be used to obtain the value itself.

contains

boolean contains(int col, int row, String text, boolean caseInsensitive)

boolean contains(Point coord, int dx, int dy, String text, boolean caseInsensitive)

boolean contains(Point coord, String text, boolean caseInsensitive)

Tests whether the cell indicated by its coordinates contains a value (raw, evaluated, or formatted) that contains specified text. The primary purpose for this function is for condition and highlight expressions.

count

int count(Iterator iterator)

Returns the number of elements returned by the iterator. Typically used in conjuction with condition.

deref

Object deref(int x, int y)

Object deref(Point coord, int dx, int dy)

Object deref(Point coord)

Returns the value of the cell indicated by its coordinates and sets up a dependency to the current cell (cell at position (col, row)). In the case of using coordinate offsets (dx and dy), the result is deref(coord.x + dx, coord.y + dy).

highlight

Iterator highlight(Iterator iterator, String expression, Appearance trueAppearance, Appearance falseAppearance)

Iterator highlight(Iterator iterator, String expression, Color trueBgColor, Color falseBgColor)

Returns an Iterator that iterates through a subset of elements much like condition, except it highlights results of expression evaluation as it steps through underlying iterator object. This function requires that iterator be in compliance with Bean Sheet's range iteration rules.

max

Object max(Iterator range)

Returns the maximum value from cell range. Values in the range must be either primitive numerical types or implementations of Comparable interface.

min

Object min(Iterator range)

Returns the minimum value from cell range. Values in the range must be either primitive numerical types or implementations of Comparable interface.

now

java.util.Date now()

Shorthand for setCell(new java.util.Date()).

range

Iterator range(String rangeString)

Returns a cell range iterator specified by rangeString. With the current syntax supporting [<col name><row index>:<col name><row index>] range notation, this command rarely needs to be explicitly called.

setCell

Object setCell(Object val)

Returns and sets current cell's value to val.

sum

double sum(Iterator range)

Returns a numerical sum of cell values in the range provided.