GloopMethods
The GloopMethods
class contains a series of utility methods that are
intended for use in Gloop only. These include:
- Java system utility methods;
- methods for running scripts;
- methods for working with cursors;
- throwing exceptions; and
- creating Gloop models.
Not for Groovy
Most of the methods in GloopMethods
deal with Gloop-specific objects; the remaining utility methods are already
supported natively by Groovy and thus, this class does not provide much value for Groovy code.
getSystemTime
Use GloopMethods.getSystemTime()
to get the current system time.
Return value
This method will return the system time in milliseconds as a long
property.
Usage
getSystemProperty
Use GloopMethods.getSystemProperty(String, String)
to get a Java system property. This
method is a wrapper for the java.lang.System.getProperty(String, String)
method.
Parameters
Property | Type | Description |
---|---|---|
name |
java.lang.String |
The name of the property to get. |
defaultVal |
java.lang.String |
The default return value if the property isn't set yet. |
Return value
This method will return a String
property if the property exists; otherwise, null
.
Usage
setSystemProperty
Use GloopMethods.setSystemProperty(String, String)
to set a Java system property. This method is a wrapper for the
java.lang.System.setProperty(String, String)
method.
Parameters
Property | Type | Description |
---|---|---|
name |
java.lang.String |
The name of the property to set. |
value |
java.lang.String |
The value to assign to the system property. |
Return value
This method will return the configured value for the property.
Usage
runScriptlet
Use the GloopMethods.runScriptlet(String, GloopExecutionContext)
method to run a piece of Groovy code in the current
context.
Parameters
Property | Type | Description |
---|---|---|
scriptlet |
java.lang.String |
The groovy code snippet to execute agains the current context. |
context |
The Gloop execution context; Gloop maps this automatically. |
Return value
The method will return the output of the scriptlet as a java.lang.Object
.
Usage
contextToJsonString
This method creates a JSON representation of the current Gloop variable context.
Parameters
Property | Type | Description |
---|---|---|
context |
The Gloop execution context; Gloop maps this automatically. |
Return value
This method returns a JSON string representing the Gloop context.
Usage
cursorHasNext
Use the GloopMethods.cursorHasNext(GloopCursor)
method to check whether or not the given Gloop cursor
has another record.
Parameters
Property | Type | Description |
---|---|---|
cursor |
io.toro.gloop.object.cursor.GloopCursor |
The Gloop cursor to be checked. |
Return value
A boolean property; true
if the cursor has another record; `false otherwise.
Usage
cursorNextRecord
Use this method to point the cursor to the next record.
Parameters
Property | Type | Description |
---|---|---|
cursor |
io.toro.gloop.object.cursor.GloopCursor |
The Gloop cursor which must point to the next record. |
Usage
cursorGetValue
Use the GloopMethods.cursorGetValue(GloopCursor)
method to get the value of the given cursor's current record.
Parameters
Property | Type | Description |
---|---|---|
cursor |
io.toro.gloop.object.cursor.GloopCursor |
The Gloop cursor whose record will be read. |
Return value
This method returns the current record the Gloop cursor is pointing to as a java.lang.Object
.
Usage
cursorAppend
Use this method to add a new record to the cursor. If the value received is a collection or and array, elements will be iterated and added individually.
Parameters
Property | Type | Description |
---|---|---|
cursor |
io.toro.gloop.object.cursor.GloopCursor |
The Gloop cursor whose records will be modified. |
value |
java.lang.Object |
The value(s) to add to the cursor. |
Usage
cursorSize
Use the GloopMethods.cursorSize(GloopCursor)
method to get the size of a given cursor.
Parameters
Property | Type | Description |
---|---|---|
cursor |
io.toro.gloop.object.cursor.GloopCursor |
The Gloop cursor whose records will be counted. |
Return value
A long property whose value is set to the number of records held by the cursor.
Usage
cursorSkip
Use the GloopMethods.cursorSkip(GloopCursor, int)
method to skip the next n record(s) of a given cursor.
Parameters
Property | Type | Description |
---|---|---|
cursor |
io.toro.gloop.object.cursor.GloopCursor |
The Gloop cursor with records to skip. |
skipCount |
java.lang.Integer |
The number of records to skip over. |
Return value
The number of records actually skipped.
Usage
cursorLast
Use the GloopMethods.cursorLast(GloopCursor)
method to iterate through the cursor until the last record is reached.
Parameters
Property | Type | Description |
---|---|---|
cursor |
io.toro.gloop.object.cursor.GloopCursor |
The Gloop cursor whose last record must be reached. |
Return value
The number of records skipped over.
Usage
cursorClose
Use the GloopMethods.cursorClose(GloopCursor)
method to close a given cursor.
Parameters
Property | Type | Description |
---|---|---|
cursor |
io.toro.gloop.object.cursor.GloopCursor |
The Gloop cursor to close. |
Usage
cursorToArray
Use the GloopMethods.cursorToArray(GloopCursor)
method to iterate through a cursor and create an in-memory array of
Gloop models of its records.
Parameters
Property | Type | Description |
---|---|---|
cursor |
io.toro.gloop.object.cursor.GloopCursor |
The Gloop cursor whose records shall be copied. |
Return value
This method returns a io.toro.gloop.object.property.GloopModel
containing all cursor data.
Usage
throwException(String)
Use the GloopMethods.throwException(String)
method to throw an exception with the configured message.
Parameters
Property | Type | Description |
---|---|---|
message |
java.lang.String |
The exception message. |
Usage
throwException(String, Throwable)
Use the GloopMethods.throwException(String, Throwable)
method throw an exception with the configured message and
cause (of type Throwable
).
Parameters
Property | Type | Description |
---|---|---|
message |
java.lang.String |
The exception message. |
cause |
java.lang.Throwable |
The cause of the exception or null if the cause is non-existent or unknown. |
Usage
dynamicModelToMapModelArray
Use this method to create a map-like Gloop model out of a given Gloop model. The result is an array of Gloop models;
each with name
and value
properties. Every property in the source Gloop model will have its own entry in the
resulting array. In these entries, the property name is mapped to the name
property, and the value mapped to the
value
.
Example transformation using the dynamicModelToMapModelArray(GloopModel)
method
For this example, let's assume the source Gloop model is the model below, represented in JSON:
1 2 3 4 | { "TORO": "Cloud", "Martini": "Ninja" } |
When this method is used, the resulting array will be:
1 2 3 4 5 6 7 8 9 10 | [ { "name": "TORO", "value": "Cloud" }, { "name": "Martini", "value": "Ninja" } ] |
Parameters
Property | Type | Description |
---|---|---|
anonymousModel |
io.toro.gloop.object.property.GloopModel |
The Gloop model to be converted. |
Return value
This method returns an array of io.toro.gloop.object.property.GloopModel
s; each model representing a property
of anonymousModel
.
Usage
mapModelArrayToDynamicModel
mapModelArrayToDynamicModel(GloopModel)
is used to create a model out of an array of models. Each model in the source
array follows a specific structure; with a name
and value
property each. Using said method, the resulting Gloop
model would have properties named after name
properties and their values equal to the corresponding value
property
of each source model.
This method is the reverse counterpart of dynamicModelToMapModelArray(GloopModel)
.
Example transformation using the mapModelArrayToDynamicModel(GloopModel)
method
Given the source array of models:
1 2 3 4 5 6 7 8 9 10 | [ { "name": "TORO", "value": "Cloud" }, { "name": "Martini", "value": "Ninja" } ] |
... the output of this method would be:
1 2 3 4 | { "TORO": "Cloud", "Martini": "Ninja" } |
Parameters
Property | Type | Description |
---|---|---|
model |
io.toro.gloop.object.property.GloopModel |
The Gloop model to be converted. |
Return value
This method returns a new io.toro.gloop.object.property.GloopModel
, containing properties described by the source
array of models.