Interface JsSet
- All Superinterfaces:
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.
- Since:
- 7.20
-
Method Summary
Modifier and TypeMethodDescriptionAdds the specifiedelementto this set.voidclear()Removes all elements from this set.booleanRemoves the specifiedelementfrom this set.booleanReturns true if this set contains the specifiedelement.longsize()Returns the number of elements in this set.toSet()Converts this set to aSet.<T> Set<T>Converts this set to aSet.Methods inherited from interface com.teamdev.jxbrowser.js.JsObject
call, close, frame, hasProperty, hasProperty, ownPropertyNames, ownPropertySymbols, property, property, propertyNames, putProperty, putProperty, removeProperty, removeProperty
-
Method Details
-
add
Adds the specifiedelementto this set.The type mapping rules are the following:
| Java | JavaScript | |--------------------|-------------------------------| | Double | Number | | BigInteger | BigInt | | String | String | | Boolean | Boolean | | JsSymbol | Symbol | | 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
JsAccessibleannotation or via theJsAccessibleTypesclass.Java collections that are not made accessible to JavaScript using the
JsAccessibleannotation or via theJsAccessibleTypesclass 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
JsAccessibleannotation or via theJsAccessibleTypesclass are wrapped into a JavaScript proxy object. Such proxy objects can be used to modify the collection in Java.- Parameters:
element- the element to insert- Returns:
- this set
- Throws:
IllegalArgumentException- whenelementis aJsObjectfrom a different web page or frameObjectClosedException- when the JavaScript object is already disposed or invalid
-
has
Returns true if this set contains the specifiedelement.- Parameters:
element- the element whose presence in this test is tested- Returns:
trueif this set contains the specifiedelement- Throws:
ObjectClosedException- when the JavaScript object is already disposed or invalid
-
delete
Removes the specifiedelementfrom this set.- Parameters:
element- the element to be removed from this set- Returns:
trueif this set contained the specifiedelement- Throws:
ObjectClosedException- when the JavaScript object is already disposed or invalid
-
size
long size()Returns the number of elements in this set. -
clear
void clear()Removes all elements from this set. Does nothing if the set is empty. -
toSet
Converts this set to aSet.The type mapping rules for the set elements are the following:
| JavaScript | Java | |--------------------|----------------| | Number | Double | | BigInt | BigInteger | | String | String | | Boolean | Boolean | | Symbol | JsSymbol | | 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.
- Returns:
- a set containing the converted elements from this set
- Throws:
ObjectClosedException- when the JavaScript object is already disposed or invalid
-
toSet
Converts this set to aSet.The type mapping rules for the set elements are the following:
| JavaScript | Java | |--------------------|----------------| | Number | Double | | BigInt | BigInteger | | String | String | | Boolean | Boolean | | Symbol | JsSymbol | | 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
Taccording to the mapping rules.- Type Parameters:
T- the type of the converted elements- Parameters:
type- the Java type to convert elements in this set to, according to the mapping rules- Returns:
- a set containing the converted elements from this set
- Throws:
ObjectClosedException- when the JavaScript object is already disposed or invalid
-