|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object sleep.runtime.SleepUtils
public class SleepUtils
This class contains generalized utilities for instantiating/wrapping data into the sleep Scalar type. Included for free are methods for executing sleep blocks as well.
Block
,
SleepClosure
,
Scalar
,
ScalarType
,
ScalarArray
,
ScalarHash
Field Summary | |
---|---|
protected static ScalarType |
nullScalar
a shared instance of the dreaded null scalar... |
static int |
SLEEP_RELEASE
A date stamp of this Sleep release in YYYYMMDD format |
static java.lang.String |
SLEEP_VERSION
A string description of this Sleep release |
Constructor Summary | |
---|---|
SleepUtils()
|
Method Summary | |
---|---|
static void |
addKeyword(java.lang.String keyword)
registers "keyword" as a keyword with the parser. |
static java.lang.String |
describe(Scalar scalar)
returns a string description of the specified scalar. |
static java.lang.String |
describe(java.util.Stack arguments)
returns a comma separated list of descriptions of the scalars in the specified argument stack. |
static Scalar |
getAccessOrderedHashScalar()
returns an empty access ordered hashmap scalar |
static java.util.Stack |
getArgumentStack(java.util.Map pairs)
Generate a java.util.Stack of sleep.bridges.KeyValuePair arguments from a Map. |
static Scalar |
getArrayScalar()
returns a Scalar variable containing a SLEEP array as its value (everything in SLEEP is stored as a Scalar |
static Scalar |
getArrayScalar(ScalarArray value)
Creates a scalar with the specified ScalarArray as the value |
static Scalar |
getArrayWrapper(java.util.Collection dataStructure)
An easy way to make your programs data structures available in the script environment. |
static Scalar |
getEmptyScalar()
returns the null scalar, which will always be equal to 0, "", and null simultaneously. |
static SleepClosure |
getFunctionFromScalar(Scalar value)
extracts a callable Function from the passed in Scalar. |
static SleepClosure |
getFunctionFromScalar(Scalar value,
ScriptInstance script)
extracts a callable Function from the passed in Scalar. |
static Scalar |
getHashScalar()
returns an empty hashmap scalar |
static Scalar |
getHashScalar(ScalarHash value)
Creates a scalar with the specified ScalarHash as the value |
static Scalar |
getHashWrapper(java.util.Map dataStructure)
An easy way to make your programs data structures available in the script environment. |
static IOObject |
getIOHandle(java.io.InputStream in,
java.io.OutputStream out)
creates an IO handle scalar suitable for use with the sleep IO API. |
static Scalar |
getIOHandleScalar(java.io.InputStream in,
java.io.OutputStream out)
creates an IO handle scalar suitable for use with the sleep IO API. |
static java.util.Iterator |
getIterator(Scalar temp,
ScriptInstance script)
Returns a scalar iterator depending grabbed from the Scalar. |
static java.util.List |
getListFromArray(Scalar array)
Generate a java.util.List from a scalar array. |
static java.util.List |
getListFromArray(ScalarArray array)
Generate a java.util.List from a scalar array. |
static java.util.Map |
getMapFromHash(Scalar map)
Generate a java.util.Map from a scalar hash. |
static java.util.Map |
getMapFromHash(ScalarHash map)
Generate a java.util.Map from a scalar hash. |
static Scalar |
getOrderedHashScalar()
returns an empty insertion ordered hashmap scalar |
static Scalar |
getScalar(boolean x)
if x is true, the value will be 1, if x is false the value will be the empty scalar |
static Scalar |
getScalar(byte[] x)
constructs a string scalar with value x interpreted as an array of unsigned bytes |
static Scalar |
getScalar(byte[] x,
int length)
constructs a string scalar with value x interpreted as an array of unsigned bytes |
static Scalar |
getScalar(double x)
returns a double scalar with value x |
static Scalar |
getScalar(float x)
returns a double scalar (coverted from the float) with value x |
static Scalar |
getScalar(int x)
returns an int scalar with value x |
static Scalar |
getScalar(long x)
returns a long scalar with value x |
static Scalar |
getScalar(java.lang.Object x)
returns an object scalar with value x |
static Scalar |
getScalar(Scalar x)
Forces a copy of the value of the passed in scalar to be made. |
static Scalar |
getScalar(short x)
returns an int scalar (coverted from the short) with value x |
static Scalar |
getScalar(java.lang.String x)
returns a string scalar with value x |
static boolean |
isEmptyScalar(Scalar value)
returns true if the passed in scalar value is equivalent to the empty scalar or null |
static boolean |
isFunctionScalar(Scalar value)
Determines if the passed in scalar represents a "function" value. |
static boolean |
isTrueScalar(Scalar value)
check if the scalar is true using Sleep's definition of truth. |
static java.lang.Object |
newInstance(java.lang.Class initializeMe,
Block code,
ScriptInstance owner)
Creates a proxy instance of the specified class (limited to interfaces at this time) that is backed with the specified block of code (made into a closure) |
static java.lang.Object |
newInstance(java.lang.Class initializeMe,
SleepClosure closure,
ScriptInstance owner)
Creates a proxy instance of the specified class (limited to interfaces at this time) that is backed with the specified closure |
static Block |
ParseCode(java.lang.String code)
Parses the specified code into a runnable block. |
static void |
removeScalar(java.util.Iterator collection,
Scalar value)
Iterates over the specified collection and removes all items that are the same as the specified scalar value. |
static Scalar |
runCode(Block code,
ScriptEnvironment env)
"safely" run a snippet of code. |
static Scalar |
runCode(Function func,
java.lang.String name,
ScriptInstance script,
java.util.Stack locals)
"safely" runs a "Function" of code. |
static Scalar |
runCode(ScriptInstance owner,
Block code)
"safely" run a snippet of code. |
static Scalar |
runCode(ScriptInstance script,
Block code,
java.util.HashMap vars)
"safely" run a snippet of code. |
static Scalar |
runCode(SleepClosure closure,
java.lang.String message,
ScriptInstance script,
java.util.Stack locals)
"safely" runs a closure. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int SLEEP_RELEASE
public static final java.lang.String SLEEP_VERSION
protected static ScalarType nullScalar
Constructor Detail |
---|
public SleepUtils()
Method Detail |
---|
public static void addKeyword(java.lang.String keyword)
public static Block ParseCode(java.lang.String code) throws YourCodeSucksException
YourCodeSucksException
public static void removeScalar(java.util.Iterator collection, Scalar value)
public static Scalar runCode(Block code, ScriptEnvironment env)
code
- the block of code we want to executeenv
- the environment to run the code in
public static Scalar runCode(SleepClosure closure, java.lang.String message, ScriptInstance script, java.util.Stack locals)
closure
- the SleepClosure object we want to executemessage
- the $0 parameter (aka the message) to pass to this closure objectscript
- the script we want to execute the function withinlocals
- a stack of scalars representing the arguments to this Function (first arg on top)
public static Scalar runCode(Function func, java.lang.String name, ScriptInstance script, java.util.Stack locals)
func
- the Function object we want to executename
- the name of the function we are executing (can be anything, depending on the function object)script
- the script we want to execute the function withinlocals
- a stack of scalars representing the arguments to this Function (first arg on top)
public static Scalar runCode(ScriptInstance script, Block code, java.util.HashMap vars)
script
- the owning script instance of this block of codecode
- the block of code we want to executevars
- a hashmap containing Scalar objects that should be installed into the local scope. The keys should be Strings representing the $names for each of the Scalar variables. This value can be null.
public static Scalar runCode(ScriptInstance owner, Block code)
owner
- the owning script instance of this block of codecode
- the block of code we want to execute
public static Scalar getArrayWrapper(java.util.Collection dataStructure)
public static Scalar getHashWrapper(java.util.Map dataStructure)
public static Scalar getHashScalar(ScalarHash value)
public static Scalar getArrayScalar(ScalarArray value)
public static Scalar getArrayScalar()
public static java.util.Map getMapFromHash(Scalar map)
public static java.util.Map getMapFromHash(ScalarHash map)
public static java.util.Stack getArgumentStack(java.util.Map pairs)
public static java.util.Iterator getIterator(Scalar temp, ScriptInstance script)
public static java.util.List getListFromArray(Scalar array)
public static java.util.List getListFromArray(ScalarArray array)
public static Scalar getEmptyScalar()
public static boolean isEmptyScalar(Scalar value)
public static boolean isFunctionScalar(Scalar value)
public static SleepClosure getFunctionFromScalar(Scalar value)
public static SleepClosure getFunctionFromScalar(Scalar value, ScriptInstance script)
public static Scalar getIOHandleScalar(java.io.InputStream in, java.io.OutputStream out)
public static IOObject getIOHandle(java.io.InputStream in, java.io.OutputStream out)
public static java.lang.Object newInstance(java.lang.Class initializeMe, SleepClosure closure, ScriptInstance owner)
public static java.lang.Object newInstance(java.lang.Class initializeMe, Block code, ScriptInstance owner)
public static java.lang.String describe(java.util.Stack arguments)
public static java.lang.String describe(Scalar scalar)
public static Scalar getHashScalar()
public static Scalar getOrderedHashScalar()
public static Scalar getAccessOrderedHashScalar()
public static Scalar getScalar(int x)
public static Scalar getScalar(short x)
public static Scalar getScalar(float x)
public static Scalar getScalar(double x)
public static Scalar getScalar(Scalar x)
public static Scalar getScalar(long x)
public static Scalar getScalar(byte[] x)
public static Scalar getScalar(byte[] x, int length)
public static Scalar getScalar(java.lang.String x)
public static Scalar getScalar(java.lang.Object x)
public static Scalar getScalar(boolean x)
public static boolean isTrueScalar(Scalar value)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |