Class BasicArrayValue
- All Implemented Interfaces:
Value,BasicArray,BasicValue<Object[]>,RightValue
-
Field Summary
Fields inherited from interface com.scriptbasic.spi.BasicValue
FALSE, TRUE -
Constructor Summary
ConstructorsConstructorDescriptionThis constructor can be used by extension classes to instantiate a new BasicArrayValue when the extension function does not have access to the interpreter.BasicArrayValue(Interpreter interpreter) Create a new BasicArrayValue and remember the interpreter. -
Method Summary
Modifier and TypeMethodDescriptionGet theindex-th element of the array.longGet the length of the array.Object[]getValue()voidSet the index-th element of the arrayvoidSet the array object.final voidsetInterpreter(Interpreter interpreter) Set the interpreter that this array belongs to.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.scriptbasic.spi.RightValue
isArray, isBoolean, isDate, isDouble, isJavaObject, isLong, isNumeric, isString
-
Constructor Details
-
BasicArrayValue
public BasicArrayValue()This constructor can be used by extension classes to instantiate a new BasicArrayValue when the extension function does not have access to the interpreter.Note that in later versions this constructor will be deprecated as soon as the interface of the extensions will make it possible to pass the interpreter along to the extension methods.
-
BasicArrayValue
Create a new BasicArrayValue and remember the interpreter.The interpreter can determine the maximum size allowed for arrays and therefore may suggest for a BasicArrayValue not to extend its size, but rather throw exception. This is to prevent allocating extraordinary large arrays in an interpreter by mistake.
- Parameters:
interpreter- parameter
-
-
Method Details
-
setArray
Description copied from interface:BasicArraySet the array object. This method is available as a convenience method for extension methods and is not used by the interpreter. This method can be used when the array is available from some calculation and it would be waste of resource to copy the elements of the array one by one callingBasicArray.set(Integer, Object).- Specified by:
setArrayin interfaceBasicArray- Parameters:
array- the array- Throws:
ScriptBasicException- when the array is null
-
setInterpreter
Set the interpreter that this array belongs to.Note that this method is used only from the code where the interpreter calls an extension method that returns a BasicArrayValue. In that case the parameter less constructor of this class is called by the extension method and thus the BasicArrayValue does not know the interpreter and can not request suggestion from the interpreter to perform resizing or throw exception.
When the parameterless version of the constructor becomes deprecated this setter will also become deprecated.
- Parameters:
interpreter- parameter
-
getLength
public long getLength()Description copied from interface:BasicArrayGet the length of the array. This is not the length of the underlying object array but the size that the BASIC program should feel.- Specified by:
getLengthin interfaceBasicArray- Returns:
- the length of the array, which is n+1, where n is the maximal index of the array the BASIC program ever used.
-
set
Description copied from interface:BasicArraySet the index-th element of the array- Specified by:
setin interfaceBasicArray- Parameters:
index- parameterobject- the new value for the array- Throws:
ScriptBasicException- in case of exception
-
get
Description copied from interface:BasicArrayGet theindex-th element of the array. Note that this method does NOT convert the value to an ordinary Java object. Thus when calling this method from an extension method be prepared to convert the value to ordinary Java object yourself.- Specified by:
getin interfaceBasicArray- Parameters:
index- parameter- Returns:
- the array element.
- Throws:
ScriptBasicException- in case of exception
-
toString
-
getValue
- Specified by:
getValuein interfaceBasicValue<Object[]>
-