Interface ProxyArray

All Superinterfaces:
Proxy, ProxyIterable

public interface ProxyArray extends ProxyIterable
Interface to be implemented to mimic guest language arrays. Arrays are always interpreted as zero-based arrays, independent of whether the Graal language uses one-based arrays. For example an access to array index one in a language with one-based arrays will access the proxy array at index zero.
Since:
19.0
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static ProxyArray
    fromArray(Object... values)
    Creates a proxy array backed by a Java Object array.
    static ProxyArray
    fromList(List<Object> values)
    Creates a proxy array backed by a Java List.
    get(long index)
    Returns the element at the given index.
    default Object
    Returns an iterator.
    long
    Returns the reported size of the array.
    default boolean
    remove(long index)
    Removes the element at the given index.
    void
    set(long index, Value value)
    Sets the element at the given index.
  • Method Details

    • get

      Object get(long index)
      Returns the element at the given index.
      Throws:
      ArrayIndexOutOfBoundsException - if the index is out of bounds
      UnsupportedOperationException - if the operation is not supported
      Since:
      19.0
    • set

      void set(long index, Value value)
      Sets the element at the given index.
      Throws:
      ArrayIndexOutOfBoundsException - if the index is out of bounds
      UnsupportedOperationException - if the operation is not supported
      Since:
      19.0
    • remove

      default boolean remove(long index)
      Removes the element at the given index.
      Returns:
      true when the element was removed, false when the element didn't exist.
      Throws:
      ArrayIndexOutOfBoundsException - if the index is out of bounds
      UnsupportedOperationException - if the operation is not supported
      Since:
      19.0
    • getSize

      long getSize()
      Returns the reported size of the array. The returned size of an array does not limit a guest language to get and set values using arbitrary indices. The array size is typically used by Graal languages to traverse the array.
      Since:
      19.0
    • getIterator

      default Object getIterator()
      Returns an iterator. The returned object must be interpreted as an iterator using the semantics of Context.asValue(Object) otherwise an IllegalStateException is thrown. Examples for valid return values are:
      Specified by:
      getIterator in interface ProxyIterable
      Since:
      20.1
      See Also:
    • fromArray

      static ProxyArray fromArray(Object... values)
      Creates a proxy array backed by a Java Object array. If the set values of the array are host values then they will be unboxed. Note this function expects a variable number of arguments of type Object, thus might not work as expected on non-Object array types. For instance, an int array will be stored as the first element of the resulting proxy array. To flatten it out, convert it to an Object array first (e.g. with Arrays.stream( myIntArray ).boxed().toArray();).
      Parameters:
      values - the Object[] array or the vararg arguments to be proxied.
      Since:
      19.0
    • fromList

      static ProxyArray fromList(List<Object> values)
      Creates a proxy array backed by a Java List. If the set values of the list are host values then the they will be unboxed.
      Since:
      19.0