Class BasicArrayValue

java.lang.Object
com.scriptbasic.executors.rightvalues.BasicArrayValue
All Implemented Interfaces:
Value, BasicArray, BasicValue<Object[]>, RightValue

public class BasicArrayValue extends Object implements RightValue, BasicArray, BasicValue<Object[]>
  • 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

      public BasicArrayValue(Interpreter interpreter)
      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

      public void setArray(Object[] array) throws ScriptBasicException
      Description copied from interface: BasicArray
      Set 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 calling BasicArray.set(Integer, Object).
      Specified by:
      setArray in interface BasicArray
      Parameters:
      array - the array
      Throws:
      ScriptBasicException - when the array is null
    • setInterpreter

      public final void setInterpreter(Interpreter interpreter)
      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: BasicArray
      Get 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:
      getLength in interface BasicArray
      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

      public void set(Integer index, Object object) throws ScriptBasicException
      Description copied from interface: BasicArray
      Set the index-th element of the array
      Specified by:
      set in interface BasicArray
      Parameters:
      index - parameter
      object - the new value for the array
      Throws:
      ScriptBasicException - in case of exception
    • get

      public Object get(Integer index) throws ScriptBasicException
      Description copied from interface: BasicArray
      Get the index-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:
      get in interface BasicArray
      Parameters:
      index - parameter
      Returns:
      the array element.
      Throws:
      ScriptBasicException - in case of exception
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getValue

      public Object[] getValue()
      Specified by:
      getValue in interface BasicValue<Object[]>