Top Description Methods
org.graalvm.polyglot.proxy

public Interface ProxyArray

Additional top-level class in compilation unit: DefaultProxyArrayIterator.

extends ProxyIterable
Known Direct Implementers
org.graalvm.polyglot.proxy.ProxyHashMapImpl.ProxyEntryImpl
Imports
java.util.List, .NoSuchElementException, org.graalvm.polyglot.Value

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
Proxy

Method Summary

Modifier and TypeMethod and Description
public static ProxyArray
fromArray(Object...
the Object[] array or the vararg arguments to be proxied.
values
)

Creates a proxy array backed by a Java Object array.

public static ProxyArray
fromList(List<Object> values)

Creates a proxy array backed by a Java List.

public Object
get(long index)

Returns the element at the given index.

public default Object
public long
getSize()

Returns the reported size of the array.

public default boolean

Returns:

true when the element was removed, false when the element didn't exist.
remove
(long index)

Removes the element at the given index.

public void
set(long index, Value value)

Sets the element at the given index.

Inherited from org.graalvm.polyglot.proxy.ProxyIterable:
from

Method Detail

fromArrayback to summary
public 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:Object[]

the Object[] array or the vararg arguments to be proxied.

Since
19.0
fromListback to summary
public 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
getback to summary
public Object get(long index)

Returns the element at the given index.

Exceptions
ArrayIndexOutOfBoundsException:
if the index is out of bounds
UnsupportedOperationException:
if the operation is not supported
Since
19.0
getIteratorback to summary
public default Object getIterator()

Implements org.graalvm.polyglot.proxy.ProxyIterable.getIterator.

Doc from org.graalvm.polyglot.proxy.ProxyIterable.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:

Annotations
@Override
Since
20.1
getSizeback to summary
public 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
removeback to summary
public default boolean remove(long index)

Removes the element at the given index.

Returns:boolean

true when the element was removed, false when the element didn't exist.

Annotations
@SuppressWarnings:unused
Exceptions
ArrayIndexOutOfBoundsException:
if the index is out of bounds
UnsupportedOperationException:
if the operation is not supported
Since
19.0
setback to summary
public void set(long index, Value value)

Sets the element at the given index.

Exceptions
ArrayIndexOutOfBoundsException:
if the index is out of bounds
UnsupportedOperationException:
if the operation is not supported
Since
19.0