public interface JsSet extends JsObject
A set object can be passed between Java and JavaScript as a method argument or a return value. The object lifetime is bound to the lifetime of the frame this object belongs to. When the owner frame is unloaded, all the JavaScript objects are automatically disposed.
An attempt to access a disposed JavaScript object will result in
IllegalStateException
.
Modifier and Type | Method and Description |
---|---|
JsSet |
add(java.lang.Object element)
Adds the specified
element to this set. |
void |
clear()
Removes all elements from this set.
|
boolean |
delete(java.lang.Object element)
Removes the specified
element from this set. |
boolean |
has(java.lang.Object element)
Returns true if this set contains the specified
element . |
long |
size()
Returns the number of elements in this set.
|
java.util.Set<java.lang.Object> |
toSet()
Converts this set to a
Set . |
<T> java.util.Set<T> |
toSet(java.lang.Class<T> type)
Converts this set to a
Set . |
call, frame, hasProperty, ownPropertyNames, property, propertyNames, putProperty, removeProperty
JsSet add(@Nullable java.lang.Object element)
element
to this set.
The type mapping rules are the following:
| Java | JavaScript |
|--------------------|-------------------------------|
| Double | Number |
| String | String |
| Boolean | Boolean |
| null | null |
| JsObject | Object |
| Node | Node |
| List<?> | Array or Proxy Object |
| Set<?> | Set or Proxy Object |
| Map<?,?> | Map or Proxy Object |
| byte[] | ArrayBuffer |
| Object | Proxy Object |
If you pass a non-primitive Java object to JavaScript, it will be converted into a
"proxy" JavaScript object. Method and property calls to this object will be delegated to
the Java object. For security reasons, JavaScript can access only those methods and fields
of the injected Java object that are explicitly marked as accessible either using the
JsAccessible
annotation or via the JsAccessibleTypes
class.
Java collections that are not made accessible to JavaScript using the JsAccessible
annotation or via the JsAccessibleTypes
class are converted to JavaScript
collections. The content of the converted collection is a deep copy of the Java collection.
Modifications of the converted collection in JavaScript do not affect the collection in Java.
Java collections that are made accessible to JavaScript using the JsAccessible
annotation or via the JsAccessibleTypes
class are wrapped into a JavaScript proxy
object. Such proxy objects can be used to modify the collection in Java.
element
- the element to insertjava.lang.IllegalArgumentException
- when element
is a JsObject
from a different
web page or framejava.lang.IllegalStateException
- when the JavaScript object is already disposed or invalidboolean has(@Nullable java.lang.Object element)
element
.element
- the element whose presence in this test is testedtrue
if this set contains the specified element
java.lang.IllegalStateException
- when the JavaScript object is already disposed or invalidboolean delete(java.lang.Object element)
element
from this set.element
- the element to be removed from this settrue
if this set contained the specified element
java.lang.IllegalStateException
- when the JavaScript object is already disposed or invalidlong size()
void clear()
java.util.Set<java.lang.Object> toSet()
Set
.
The type mapping rules for the set elements are the following:
| JavaScript | Java |
|--------------------|----------------|
| Number | Double |
| String | String |
| Boolean | Boolean |
| null and undefined | null |
| Node | Node, JsObject |
| ArrayBuffer | byte[] |
| Array | List<?> |
| Set | Set<?> |
| Map | Map<?,?> |
| Object | JsObject |
| Proxy Object | Object |
Proxy objects are mapped to the corresponding injected Java object.
java.lang.IllegalStateException
- when the JavaScript object is already disposed or invalid<T> java.util.Set<T> toSet(java.lang.Class<T> type)
Set
.
The type mapping rules for the set elements are the following:
| JavaScript | Java |
|--------------------|----------------|
| Number | Double |
| String | String |
| Boolean | Boolean |
| null and undefined | null |
| Node | Node, JsObject |
| ArrayBuffer | byte[] |
| Array | List<?> |
| Set | Set<?> |
| Map | Map<?,?> |
| Object | JsObject |
| Proxy Object | Object |
Proxy objects are mapped to the corresponding injected Java object.
All elements in this set must be of a type convertible to the type T
according to the mapping rules.
T
- the type of the converted elementstype
- the Java type to convert elements in this set to, according to the mapping rulesjava.lang.IllegalStateException
- when the JavaScript object is already disposed or invalid