01_user_documentation:07_rgg_xl:02_xl:08_object:05_aggregate:02_aggregate_methods
Table of Contents
Aggregate Methods
Like filter methods, aggregate methods receive a sequence of values as input. However, their result is a single value.
When used in the code, the first two argument of the method are “combined”. The first argument given has to be an Aggregate of the Type of the second argument
public static boolean checkVal (Aggregate a, Object x) { ... } Object[] myarray = new Object[] { ... }; boolean result = checkVal( myarray ); // The method takes two arguments, but only one is given
Method declaration
The base code for a method that consume aggregate is:
public static boolean checkVal (Aggregate a, Object x) { if (a.initialize ()) { // do some initialization } if (a.isFinished ()) { // set the value in the Aggregate field to be accessible outside } else { // Increment what should happens } return false; // default return value, if the function failed }
Note:
- The return type can be any primitive or Object type
- The first argument of the method HAS to be
Aggregate - There must be AT LEAST one additional argument.
- There can be as many additional arguments as needed.
- The additional arguments can be of any types.
Access data
The aggregate use some internal variables to hold data. The result has to be pushed into:
- ival: for int, byte, char, boolean or short
- lval: a long
- fval: a float
- dval: a double
- aval: any Object
Additionally four of each of these types of variable are available to store data between the method execution. Named ival1, ival2, …
Example
The method that count object (usually node) is used in RGG:
count( (*Node* )); // using a context block count( new Sphere[] { new Sphere(), new Sphere(), ... } ); // using an array
The method is defined as:
public static long count (Aggregate a, Object value) { if (a.initialize ()) { a.lval = 0; } if (!a.isFinished ()) { a.lval++; } return 0; }
01_user_documentation/07_rgg_xl/02_xl/08_object/05_aggregate/02_aggregate_methods.txt · Last modified: 2025/09/04 11:24 by gaetan
