|
com.im.df.api 5.9 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectgroovy.lang.GroovyObjectSupport
groovy.lang.Script
com.im.df.api.support.CalculationsScriptBaseClass
public abstract class CalculationsScriptBaseClass
Custom base class that allows extra methods to be automagically injected into scripts. Mostly this comprises calculation methods like sum(), avg() etc. that can be called from the script
| Constructor Summary | |
|---|---|
CalculationsScriptBaseClass()
|
|
| Method Summary | |
|---|---|
Number |
avg(Collection<Number> args)
Generate the average of the non-null values. |
Number |
avg(Number... args)
Generate the average of the non-null values. |
String |
concat(String sep,
Collection<?> args)
Concatenates the values in the collection with the specified separator. |
String |
concat(String sep,
Object first,
Object... others)
Concatenates the values with the specified separator. |
Number |
divide(Number arg1,
Number arg2)
Divide two numbers. |
void |
each(Collection<?> c1,
Collection<?> c2,
groovy.lang.Closure closure)
Helper method to iterate in a coordinated manner over 2 collections. |
void |
each(Collection<?> c1,
Collection<?> c2,
Collection<?> c3,
groovy.lang.Closure closure)
Helper method to iterate in a coordinated manner over 3 collections. |
Class<?> |
getReturnType()
Get the type of object that this script is expected to return |
Number |
minus(Number arg1,
Number arg2)
Subtract two numbers. |
Number |
multiply(Collection<Number> args)
Generate the product of the non-null values. |
Number |
multiply(Number... args)
Generate the product of the non-null values. |
void |
setReturnType(Class<?> returnType)
Set the type of object that this script is expected to return |
Number |
sum(Collection<Number> args)
Generate the sum of the non-null values. |
Number |
sum(Number... args)
Generate the sum of the non-null values. |
| Methods inherited from class groovy.lang.Script |
|---|
evaluate, evaluate, getBinding, getProperty, invokeMethod, print, printf, printf, println, println, run, run, setBinding, setProperty |
| Methods inherited from class groovy.lang.GroovyObjectSupport |
|---|
getMetaClass, setMetaClass |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public CalculationsScriptBaseClass()
| Method Detail |
|---|
public Class<?> getReturnType()
public void setReturnType(Class<?> returnType)
returnType - new value of returnTypepublic Number sum(Number... args)
args - The values
public Number sum(Collection<Number> args)
args - The values
public Number multiply(Number... args)
args - The values
public Number multiply(Collection<Number> args)
args - The values
public Number avg(Number... args)
args - The values
public Number avg(Collection<Number> args)
args - The values
public Number minus(Number arg1,
Number arg2)
arg1 - arg2 -
public Number divide(Number arg1,
Number arg2)
arg1 - arg2 -
public String concat(String sep,
Object first,
Object... others)
sep - first - others -
public String concat(String sep,
Collection<?> args)
sep - The separatorargs - The values
null.
public void each(Collection<?> c1,
Collection<?> c2,
groovy.lang.Closure closure)
Pass in two collections, and the closure is passed the corresponding values in turn. e.g.
c1[0], c2[0] c1[1], c2[2] c1[2], c2[2] ...
and so on until one of the collections runs out of values (it is assumed that typically the collections will be of the same length.
e.g. to sum the differences in two list of number you can do something like this:
List vals1 ...
List vals2 ...
float result = 0
each(strings1, strings2) { a, b ->
result += (a - b)
}
c1 - The first collection of values to iterate through.c2 - The second collection of values to iterate through.closure - The code that will be called in each iteration to process the collection values.
public void each(Collection<?> c1,
Collection<?> c2,
Collection<?> c3,
groovy.lang.Closure closure)
each(java.util.Collection, java.util.Collection, groovy.lang.Closure) method.
c1 - The first collection of values to iterate through.c2 - The second collection of values to iterate through.closure - The code that will be called in each iteration to process the collection values.
|
com.im.df.api 5.9 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||