Skip to main content

JSet

Struct JSet 

Source
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>

Source

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
  • raw must be a valid raw JNI local reference (or null).
  • raw must 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 'local lifetime.
Source

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.

Source

pub fn into_raw(self) -> jobject

Unwrap to the raw jni type.

Source

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>

Source

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>

Source

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 supported
  • ClassCastException - if the element type isn’t compatible with the set
  • NullPointerException - if the given element is null and the set does not allow null values
  • IllegalArgumentException - if the element has a property that prevents it from being added to this set
Source

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 supported
  • ClassCastException - if the element type isn’t compatible with the set
  • NullPointerException - if the given element is null and the set does not allow null values
Source

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
Source

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 set
  • NullPointerException - if the given element is null and the set does not allow null values
Source

pub fn size(&self, env: &mut Env<'_>) -> Result<i32>

Returns the number of elements in this set.

Source

pub fn is_empty(&self, env: &mut Env<'_>) -> Result<bool>

Returns true if this set contains no elements.

Source

pub fn iterator<'env_local>( &self, env: &mut Env<'env_local>, ) -> Result<JIterator<'env_local>>

Returns an iterator (java.util.Iterator) over the elements in this set.

Methods from Deref<Target = JObject<'local>>§

Source

pub fn as_raw(&self) -> jobject

Returns the raw JNI pointer.

Trait Implementations§

Source§

impl<'local> AsRef<JCollection<'local>> for JSet<'local>

Source§

fn as_ref(&self) -> &JCollection<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JObject<'local>> for JSet<'local>

Source§

fn as_ref(&self) -> &JObject<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> AsRef<JSet<'local>> for JSet<'local>

Source§

fn as_ref(&self) -> &JSet<'local>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'local> Debug for JSet<'local>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'local> Default for JSet<'local>

Source§

fn default() -> JSet<'local>

Returns the “default value” for a type. Read more
Source§

impl<'local> Deref for JSet<'local>

Source§

type Target = JObject<'local>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'local> From<JSet<'local>> for JCollection<'local>

Source§

fn from(value: JSet<'local>) -> JCollection<'local>

Converts to this type from the input type.
Source§

impl<'local> From<JSet<'local>> for JObject<'local>

Source§

fn from(other: JSet<'local>) -> JObject<'local>

Converts to this type from the input type.
Source§

impl<'local> Reference for JSet<'local>

Source§

type Kind<'env> = JSet<'env>

The generic associated 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 more
Source§

type GlobalKind = JSet<'static>

The associated GlobalKind type should be equivalent to Kind<'static>, with the additional bound that ensures the type is Send + Sync Read more
Source§

fn as_raw(&self) -> jobject

Returns the underlying, raw crate::sys::jobject reference.
Source§

fn class_name() -> Cow<'static, JNIStr>

The fully qualified class name of the Java class represented by this reference. Read more
Source§

fn lookup_class<'caller>( env: &Env<'_>, loader_context: &LoaderContext<'_, '_>, ) -> Result<impl Deref<Target = Global<JClass<'static>>> + 'caller>

Looks up a global reference to the JClass associated with this reference. Read more
Source§

unsafe fn kind_from_raw<'env>(local_ref: jobject) -> Self::Kind<'env>

Returns a new reference type based on Self::Kind for the given reference that is tied to the specified lifetime. Read more
Source§

unsafe fn global_kind_from_raw(global_ref: jobject) -> Self::GlobalKind

Returns a ('static) reference type based on Self::GlobalKind for the given global_ref. Read more
Source§

fn is_null(&self) -> bool

Returns true if this is a null object reference
Source§

fn null<'any>() -> Self::Kind<'any>

Returns null reference based on Self::Kind

Auto Trait Implementations§

§

impl<'local> Freeze for JSet<'local>

§

impl<'local> RefUnwindSafe for JSet<'local>

§

impl<'local> Send for JSet<'local>
where 'local: 'static,

§

impl<'local> Sync for JSet<'local>
where 'local: 'static,

§

impl<'local> Unpin for JSet<'local>

§

impl<'local> UnsafeUnpin for JSet<'local>

§

impl<'local> UnwindSafe for JSet<'local>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<'local, T> Desc<'local, T> for T
where T: AsRef<T>,

Source§

type Output = T

The type that this Desc returns.
Source§

fn lookup(self, _: &mut Env<'local>) -> Result<T, Error>

Look up the concrete type from the JVM. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<'local, T> IntoAuto<'local> for T
where T: Into<JObject<'local>>,

Source§

fn auto(self) -> Auto<'local, Self>

Wraps the local reference type into an auto-delete Auto that will automatically delete the local reference when it is dropped
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.