|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object sleep.runtime.Scalar
public class Scalar
A scalar is the universal data type for sleep variables. Scalars can have numerical values of integer, double, or long. Scalars can have a string value. Scalars can also contain a reference to a scalar array, scalar hash, or a generic Java object.
Numerical and String values are stored as ScalarTypes. Arrays and Hashes are stored in ScalarArray and ScalarHash containers respectively.
Instantiating a Scalar is most easily done using the sleep.runtime.SleepUtils class. The SleepUtils class contains several static methods for creating a Scalar object from data.
The general pattern for this is a SleepUtils.getScalar(data)
methods. There are
static getScalar() methods that take a double, int, long, Object, or a String as a parameter.
There are even methods for wrapping java data structures into a scalar array or scalar hash. Methods also exist to copy data from one scalar into another new scalar.
Examples:
Scalar anInt = SleepUtils.getScalar(3); // create an int scalar Scalar aDouble = SleepUtils.getScalar(4.5); // create a double scalar Scalar aString = SleepUtils.getScalar("hello"); // string scalar Scalar anArray = SleepUtils.getArrayWrapper(new LinkedList(); // array scalar
To add a value to a Scalar array:
Scalar arrayScalar = SleepUtils.getArray(); // empty array arrayScalar.getArray().add(SleepUtils.getScalar("value"), 0);
To iterate through all of the values in a Scalar array:
Iterator i = arrayScalar.getArray().scalarIterator(); while (i.hasNext()) { Scalar temp = (Scalar)i.next(); }
To add a value to a Scalar hashtable:
Scalar hashScalar = SleepUtils.getHashScalar(); // blank hashtable Scalar temp = hashScalar.getHash().getAt(SleepUtils.getScalar("key")); temp.setValue(SleepUtils.getScalar("value"));
The second line obtains a Scalar for "key". The returned Scalar is just a container. It is possible to set the value of the returned scalar using the setValue method.
Internally scalar values in sleep are passed by value. Methods like setValue inside of the Scalar class take care of copying the value. Externally though Scalar objects are passed by reference. When you call getAt() in the ScalarHash you are obtaining a reference to a Scalar inside of the hashtable. When you change the value of the Scalar you obtained, you change the value of the Scalar in the hashtable.
SleepUtils
,
ScalarType
,
ScalarArray
,
ScalarHash
,
Serialized FormField Summary | |
---|---|
protected ScalarArray |
array
|
protected ScalarHash |
hash
|
protected ScalarType |
value
|
Constructor Summary | |
---|---|
Scalar()
|
Method Summary | |
---|---|
double |
doubleValue()
the double value of this scalar |
ScalarType |
getActualValue()
Returns the actual non-array/non-hash value this scalar contains. |
ScalarArray |
getArray()
returns a scalar array referenced by this scalar iff this scalar contains an array reference |
ScalarHash |
getHash()
returns a scalar hash referenced by this scalar iff this scalar contains a hash reference |
ScalarType |
getValue()
Returns the container for the scalars value. |
java.lang.Object |
identity()
returns an identity value for this scalar. |
int |
intValue()
the int value of this scalar |
long |
longValue()
the long value of this scalar |
java.lang.Object |
objectValue()
the object value of this scalar |
boolean |
sameAs(Scalar other)
compares two scalars in terms of their identity. |
void |
setValue(Scalar newValue)
clones the value from the specified scalar and gives this scalar a copy of the value |
void |
setValue(ScalarArray _array)
set the value of this scalar container to a scalar array |
void |
setValue(ScalarHash _hash)
set the value of this scalar container to a scalar hash |
void |
setValue(ScalarType _value)
set the value of this scalar container to a scalar value of some type |
java.lang.String |
stringValue()
the string value of this scalar |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected ScalarType value
protected ScalarArray array
protected ScalarHash hash
Constructor Detail |
---|
public Scalar()
Method Detail |
---|
public ScalarType getActualValue()
public ScalarType getValue()
public java.lang.String stringValue()
public int intValue()
public double doubleValue()
public long longValue()
public java.lang.Object objectValue()
public ScalarArray getArray()
public ScalarHash getHash()
public void setValue(ScalarType _value)
public void setValue(ScalarArray _array)
public void setValue(ScalarHash _hash)
public java.lang.Object identity()
public boolean sameAs(Scalar other)
public java.lang.String toString()
toString
in class java.lang.Object
public void setValue(Scalar newValue)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |