pub struct JSet<'local>(/* private fields */);Expand description
A java.util.Set reference, tied to a JNI local reference frame.
See the JObject documentation for more information about object references,
how to cast them, and local reference frame lifetimes.
Implementations§
Source§impl<'local> JSet<'local>
impl<'local> JSet<'local>
Sourcepub unsafe fn from_raw<'env_inner>(
env: &Env<'env_inner>,
raw: jobject,
) -> JSet<'env_inner>
pub unsafe fn from_raw<'env_inner>( env: &Env<'env_inner>, raw: jobject, ) -> JSet<'env_inner>
Creates a JSet that wraps the given raw jobject
§Safety
rawmust be a valid raw JNI local reference (ornull).rawmust be an instance of the correct Java class.- There must not be any other owning Reference wrapper for the same reference.
- The local reference must belong to the current thread and not outlive the
JNI stack frame associated with the Env
'locallifetime.
Sourcepub const fn null() -> JSet<'static>
pub const fn null() -> JSet<'static>
Creates a new null reference.
Null references are always valid and do not belong to a local reference frame. Therefore,
the returned JSet always has the 'static lifetime.
Sourcepub fn cast_local<'any_local>(
env: &mut Env<'_>,
obj: impl Reference + Into<JObject<'any_local>> + AsRef<JObject<'any_local>>,
) -> Result<JSet<'any_local>>
pub fn cast_local<'any_local>( env: &mut Env<'_>, obj: impl Reference + Into<JObject<'any_local>> + AsRef<JObject<'any_local>>, ) -> Result<JSet<'any_local>>
Cast a local reference to a JSet
This will do a runtime (IsInstanceOf) check that the object is an instance of the correct class.
Also see these other options for casting local or global references to a JSet:
§Errors
Returns Error::WrongObjectType if the IsInstanceOf check fails.
Source§impl<'local> JSet<'local>
impl<'local> JSet<'local>
Sourcepub fn as_collection(&self) -> Cast<'local, '_, JCollection<'local>>
pub fn as_collection(&self) -> Cast<'local, '_, JCollection<'local>>
Casts this JSet to a ::jni::objects::JCollection
This does not require a runtime type check since any JSet is also a ::jni::objects::JCollection
Source§impl<'local> JSet<'local>
impl<'local> JSet<'local>
Sourcepub fn add<'any_local>(
&self,
env: &mut Env<'_>,
element: impl AsRef<JObject<'any_local>>,
) -> Result<bool>
pub fn add<'any_local>( &self, env: &mut Env<'_>, element: impl AsRef<JObject<'any_local>>, ) -> Result<bool>
Adds the given element to this set if it is not already present
Returns true if the element was added, false if it was already present.
§Throws
UnsupportedOperationException- if the add operation is not supportedClassCastException- if the element type isn’t compatible with the setNullPointerException- if the given element is null and the set does not allow null valuesIllegalArgumentException- if the element has a property that prevents it from being added to this set
Sourcepub fn remove<'any_local>(
&self,
env: &mut Env<'_>,
element: impl AsRef<JObject<'any_local>>,
) -> Result<bool>
pub fn remove<'any_local>( &self, env: &mut Env<'_>, element: impl AsRef<JObject<'any_local>>, ) -> Result<bool>
Removes the given element from this set if it is present
Returns true if the element was removed.
§Throws
UnsupportedOperationException- if the remove operation is not supportedClassCastException- if the element type isn’t compatible with the setNullPointerException- if the given element is null and the set does not allow null values
Sourcepub fn clear(&self, env: &mut Env<'_>) -> Result<()>
pub fn clear(&self, env: &mut Env<'_>) -> Result<()>
Removes all of the elements from this set.
§Throws
UnsupportedOperationException- if the clear operation is not supported
Sourcepub fn contains(&self, env: &mut Env<'_>, element: &JObject<'_>) -> Result<bool>
pub fn contains(&self, env: &mut Env<'_>, element: &JObject<'_>) -> Result<bool>
Checks if the given element is present in this set.
Returns true if the element is present, false otherwise.
§Throws
ClassCastException- if the element type isn’t compatible with the setNullPointerException- if the given element is null and the set does not allow null values
Sourcepub fn size(&self, env: &mut Env<'_>) -> Result<i32>
pub fn size(&self, env: &mut Env<'_>) -> Result<i32>
Returns the number of elements in this set.
Trait Implementations§
Source§impl<'local> AsRef<JCollection<'local>> for JSet<'local>
impl<'local> AsRef<JCollection<'local>> for JSet<'local>
Source§fn as_ref(&self) -> &JCollection<'local>
fn as_ref(&self) -> &JCollection<'local>
Source§impl<'local> From<JSet<'local>> for JCollection<'local>
impl<'local> From<JSet<'local>> for JCollection<'local>
Source§fn from(value: JSet<'local>) -> JCollection<'local>
fn from(value: JSet<'local>) -> JCollection<'local>
Source§impl<'local> Reference for JSet<'local>
impl<'local> Reference for JSet<'local>
Source§type Kind<'env> = JSet<'env>
type Kind<'env> = JSet<'env>
Self::Kind type corresponds to the underlying
class type (such as JObject or JString), parameterized by the
lifetime that indicates whether the type holds a global reference
('static) or a local reference that’s tied to a JNI stack frame. Read moreSource§type GlobalKind = JSet<'static>
type GlobalKind = JSet<'static>
GlobalKind type should be equivalent to
Kind<'static>, with the additional bound that ensures the type is
Send + Sync Read moreSource§fn as_raw(&self) -> jobject
fn as_raw(&self) -> jobject
crate::sys::jobject reference.Source§fn class_name() -> Cow<'static, JNIStr>
fn class_name() -> Cow<'static, JNIStr>
Source§fn lookup_class<'caller>(
env: &Env<'_>,
loader_context: &LoaderContext<'_, '_>,
) -> Result<impl Deref<Target = Global<JClass<'static>>> + 'caller>
fn lookup_class<'caller>( env: &Env<'_>, loader_context: &LoaderContext<'_, '_>, ) -> Result<impl Deref<Target = Global<JClass<'static>>> + 'caller>
Source§unsafe fn kind_from_raw<'env>(local_ref: jobject) -> Self::Kind<'env>
unsafe fn kind_from_raw<'env>(local_ref: jobject) -> Self::Kind<'env>
Self::Kind for the given reference that is tied
to the specified lifetime. Read moreSource§unsafe fn global_kind_from_raw(global_ref: jobject) -> Self::GlobalKind
unsafe fn global_kind_from_raw(global_ref: jobject) -> Self::GlobalKind
Source§fn null<'any>() -> Self::Kind<'any>
fn null<'any>() -> Self::Kind<'any>
null reference based on Self::Kind