Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.cocoon.forms.formmodel.algorithms
Class RepeatedFormula

    java.lang.Object
      org.apache.cocoon.forms.formmodel.algorithms.AbstractBaseAlgorithm
          org.apache.cocoon.forms.formmodel.algorithms.SimpleFormula
              org.apache.cocoon.forms.formmodel.algorithms.RepeatedFormula

All Implemented Interfaces:
  CalculatedFieldAlgorithm

public class RepeatedFormula
extends SimpleFormula

An xreporter `Expression` based algorithm that repeats the formula on a set of fields.

The specified formula will be applied iterating on the specified widgets. The final result will be the result of the last iteration. From inside the formula you can access this two extra variables :

formulaResult
  The result of the previous iteration, or the result of the initial result if this is the first iteration.
formulaCurrent
  The value of the current trigger widget.

The initial result is evaluated before starting the iteration, and its value is used as a formulaResult for the first iteration.

It's possible to define nearly every cyclic arithmetic operation with this algorithm, for example :

Sum
  initial-result="0" formula="formulaResult + formulaCurrent"
Multiplication
  initial-result="1" formula="formulaResult * formulaCurrent"

More over, thru the use of advanced xreporter syntax it's possible to quickly implement also complex algorithms:

- Count all items with a price higher than 100 : eval="formulaResult + If(price > 100, 1, 0)" (read : the result is the previous result plus one if price is over 100, 0 if price is less than 100)
- Obtain a sum of all movements, wether they are positive or negative amount movements : eval="formulaResult + Abs(amount)"
- Count how many slots are empty in the 10 items box you are using for packaging : eval="formulaResult + Reminder(items, 10)"

Note: please take care that xreporter expressions are not that accurate when it comes to decimals. The default divide operator rounds the result, see http://issues.cocoondev.org/browse/XRP-115. Also consider that the available set of functions can be expanded implementing and using new ones. Please see http://outerthought.net/wqm/xreporter/en/expressions.html for an overview of xreportes expressions and `IsNullFunction` or `StringFunction` for examples of custom xreporter functions.

Version:
  $Id: RepeatedFormula.java 587759 2007-10-24 03:00:37Z vgritsenko $

Field Summary

Fields inherited from class org.apache.cocoon.forms.formmodel.algorithms.SimpleFormula
`formula`

Fields inherited from class org.apache.cocoon.forms.formmodel.algorithms.AbstractBaseAlgorithm
`triggers`

Constructor Summary
`RepeatedFormula()`

Method Summary
`Object` | `calculate(Form form, Widget parent, Datatype datatype)` Performs the actual calculation.
`org.outerj.expression.Expression` | `getInitialResult()`
`String` | `getRepeatOn()`
`void` | `setInitialResult(org.outerj.expression.Expression initialResult)`
`void` | `setRepeatOn(String iterateOn)`

Methods inherited from class org.apache.cocoon.forms.formmodel.algorithms.SimpleFormula
`getFormula, isSuitableFor, setFormula`

Methods inherited from class org.apache.cocoon.forms.formmodel.algorithms.AbstractBaseAlgorithm
`addTrigger, clearTriggers, getTriggerWidgets`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### RepeatedFormula

    public RepeatedFormula()

Method Detail

### calculate

    public Object calculate(Form form,
                            Widget parent,
                            Datatype datatype)

  Description copied from interface: `CalculatedFieldAlgorithm`
  Performs the actual calculation.

  Specified by:
    `calculate` in interface `CalculatedFieldAlgorithm`
  Overrides:
    `calculate` in class `SimpleFormula`

### getInitialResult

    public org.outerj.expression.Expression getInitialResult()

  Returns:
    Returns the initialResult.

### setInitialResult

    public void setInitialResult(org.outerj.expression.Expression initialResult)

  Parameters:
    `initialResult` - The initialResult to set.

### getRepeatOn

    public String getRepeatOn()

  Returns:
    Returns the iterateOn.

### setRepeatOn

    public void setRepeatOn(String iterateOn)

  Parameters:
    `iterateOn` - The iterateOn to set.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 1999-2008 The Apache Software Foundation. All Rights Reserved.