Package org.graalvm.polyglot.proxy
Interface ProxyArray
- All Superinterfaces:
Proxy
,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 TypeMethodDescriptionstatic ProxyArray
Creates a proxy array backed by a Java Object array.static ProxyArray
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
getSize()
Returns the reported size of the array.default boolean
remove
(long index) Removes the element at the given index.void
Sets the element at the given index.
-
Method Details
-
get
Returns the element at the given index.- Throws:
ArrayIndexOutOfBoundsException
- if the index is out of boundsUnsupportedOperationException
- if the operation is not supported- Since:
- 19.0
-
set
Sets the element at the given index.- Throws:
ArrayIndexOutOfBoundsException
- if the index is out of boundsUnsupportedOperationException
- 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 boundsUnsupportedOperationException
- 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
Returns an iterator. The returned object must be interpreted as an iterator using the semantics ofContext.asValue(Object)
otherwise anIllegalStateException
is thrown. Examples for valid return values are:ProxyIterator
Iterator
, requireshost iterable access
- A guest language object representing an iterator
- Specified by:
getIterator
in interfaceProxyIterable
- Since:
- 20.1
- See Also:
-
fromArray
Creates a proxy array backed by a Java Object array. If the set values of the array are host values then they will beunboxed
. 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. withArrays.stream( myIntArray ).boxed().toArray();
).- Parameters:
values
- the Object[] array or the vararg arguments to be proxied.- Since:
- 19.0
-
fromList
Creates a proxy array backed by a Java List. If the set values of the list are host values then the they will beunboxed
.- Since:
- 19.0
-