sleep.bridges
Class BridgeUtilities
public
class
BridgeUtilities
extends Object
A bridge is a class that bridges your applications API and sleep. Bridges are created using interfaces from the sleep.interfaces package. Arguments are passed to bridges generally in a java.util.Stack form. The Stack of arguments contains sleep Scalar objects. The BridgeUtilities makes it safer and easier for you to extract Java types from arguments.
// some code to execute an internal add function, not a complete example
public class MyAddFunction implements Function
{
public Scalar evaluate(String name, ScriptInstance script, Stack arguments)
{
if (name.equals("&add"))
{
int a = BridgeUtilities.getInt(arguments, 0);
int b = BridgeUtilities.getInt(arguments, 0);
return SleepUtils.getScalar(a + b);
}
return SleepUtils.getEmptyScalar();
}
}
Method Summary |
static Map | extractNamedParameters(Stack args) extracts all named parameters from the argument stack. this method returns a Map whose keys are strings
and values are Scalars. |
static Scalar | flattenArray(Scalar fromValue, Scalar toValue) Flattens the specified scalar array. |
static Scalar | flattenIterator(Iterator i, Scalar toValue) Flattens the specified arrays within the specified iterator. |
static ScalarArray | getArray(Stack arguments) grab a sleep array, if the stack is empty a scalar array with no elements will be returned. |
static Class | getClass(Stack arguments, Class defaultValue) grab a class, if the stack is empty the default value will be returned |
static double | getDouble(Stack arguments) grab a double. if the stack is empty a 0 will be returned |
static double | getDouble(Stack arguments, double defaultValue) grab a double, if the stack is empty the default value will be returned |
static File | getFile(Stack arguments) returns a File object from a string argument, the path in the string argument is transformed such
that the character / will refer to the correct path separator for the current OS. |
static SleepClosure | getFunction(Stack arguments, ScriptInstance script) retrieves an executable Function object from the stack. |
static ScalarHash | getHash(Stack arguments) grab a sleep hash, if the stack is empty a scalar hash with no members will be returned. |
static int | getInt(Stack arguments) grab an integer. if the stack is empty 0 will be returned. |
static int | getInt(Stack arguments, int defaultValue) grab an integer, if the stack is empty the default value will be returned |
static Iterator | getIterator(Stack arguments, ScriptInstance script) grabs a scalar iterator, this can come from either an array or a closure called continuously until $null is returned. |
static KeyValuePair | getKeyValuePair(Stack arguments) Pops a Key/Value pair object off of the argument stack. |
static long | getLong(Stack arguments) grab a long. if the stack is empty 0 will be returned. |
static long | getLong(Stack arguments, long defaultValue) grab a long, if the stack is empty the default value will be returned |
static Object | getObject(Stack arguments) grab an object, if the stack is empty then null will be returned. |
static Scalar | getScalar(Stack arguments) grab a scalar, if the stack is empty the empty/null scalar will be returned. |
static String | getString(Stack arguments, String defaultValue) grab a string, if the stack is empty or if the value is null the default value will be returned. |
static ScalarArray | getWorkableArray(Stack arguments) grab a sleep array, if the grabbed array is a readonly array, a copy is returned. if the stack is empty an array with no elements will be returned. |
static int | normalize(int value, int length) normalizes the index value based on the specified length |
static byte[] | toByteArrayNoConversion(String textz) converts the specified string to an array of bytes (useful as Sleep stores byte arrays to strings) |
public static Map extractNamedParameters(Stack args)
extracts all named parameters from the argument stack. this method returns a Map whose keys are strings
and values are Scalars.
Flattens the specified scalar array. The toValue field can be null.
public static
Scalar flattenIterator(Iterator i,
Scalar toValue)
Flattens the specified arrays within the specified iterator. The toValue field can be null.
grab a sleep array, if the stack is empty a scalar array with no elements will be returned.
public static Class getClass(Stack arguments, Class defaultValue)
grab a class, if the stack is empty the default value will be returned
public static double getDouble(Stack arguments)
grab a double. if the stack is empty a 0 will be returned
public static double getDouble(Stack arguments, double defaultValue)
grab a double, if the stack is empty the default value will be returned
public static File getFile(Stack arguments)
returns a File object from a string argument, the path in the string argument is transformed such
that the character / will refer to the correct path separator for the current OS. Returns null if
no file is specified as an argument.
retrieves an executable Function object from the stack. Functions can be passed as closures
or as a reference to a built-in Sleep subroutine i.e. &my_func.
grab a sleep hash, if the stack is empty a scalar hash with no members will be returned.
public static int getInt(Stack arguments)
grab an integer. if the stack is empty 0 will be returned.
public static int getInt(Stack arguments, int defaultValue)
grab an integer, if the stack is empty the default value will be returned
public static Iterator getIterator(Stack arguments,
ScriptInstance script)
grabs a scalar iterator, this can come from either an array or a closure called continuously until $null is returned.
Pops a Key/Value pair object off of the argument stack. A Key/Value pair is created using
the => operator within Sleep scripts. If the top argument on this stack was not created using
=>, this function will try to parse a key/value pair using the pattern: [key]=[value]
public static long getLong(Stack arguments)
grab a long. if the stack is empty 0 will be returned.
public static long getLong(Stack arguments, long defaultValue)
grab a long, if the stack is empty the default value will be returned
public static Object getObject(Stack arguments)
grab an object, if the stack is empty then null will be returned.
public static
Scalar getScalar(Stack arguments)
grab a scalar, if the stack is empty the empty/null scalar will be returned.
public static String getString(Stack arguments, String defaultValue)
grab a string, if the stack is empty or if the value is null the default value will be returned.
public static
ScalarArray getWorkableArray(Stack arguments)
grab a sleep array, if the grabbed array is a readonly array, a copy is returned. if the stack is empty an array with no elements will be returned.
public static final int normalize(int value, int length)
normalizes the index value based on the specified length
public static byte[] toByteArrayNoConversion(String textz)
converts the specified string to an array of bytes (useful as Sleep stores byte arrays to strings)