java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
net.i2p.router.util.RemovableSingletonSet<E>
- Type Parameters:
E- type of element in this set
- All Implemented Interfaces:
Iterable<E>, Collection<E>, Set<E>
Singleton set with removable element support and iterator functionality.
Similar to Collections.singleton() but provides the ability to remove the single element and clear the set. Iterator supports remove(Object) operations while maintaining singleton behavior.
Does not support add() or addAll() operations as they would violate the singleton contract. Item may not be null.
Useful for scenarios requiring a single, modifiable element with standard collection interface compliance and removal capabilities.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classWalks the set's single element.Field Summary
Constructor Summary
ConstructorsConstructorDescriptionRemovableSingletonSet(E element) Rejects a null element, then holds it as the set's only member.Method Summary
All MethodsMethods inherited from class AbstractSet
equals, hashCode, removeAllMethods inherited from class AbstractCollection
add, addAll, containsAll, retainAll, toArray, toArray, toStringMethods inherited from interface Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface Set
add, addAll, containsAll, retainAll, spliterator, toArray, toArray
Field Details
_elem
The one element, null when the set is empty.
Constructor Details
RemovableSingletonSet
Rejects a null element, then holds it as the set's only member.- Parameters:
element- the sole element to hold, may not be null
Method Details
clear
public void clear()Remove the single element.- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceSet<E>- Overrides:
clearin classAbstractCollection<E>
contains
Whether the set contains the given element.- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceSet<E>- Overrides:
containsin classAbstractCollection<E>
isEmpty
public boolean isEmpty()Whether the set is empty.- Specified by:
isEmptyin interfaceCollection<E>- Specified by:
isEmptyin interfaceSet<E>- Overrides:
isEmptyin classAbstractCollection<E>- Returns:
- true once the sole element has been removed or cleared
remove
Remove the element if it matches.- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceSet<E>- Overrides:
removein classAbstractCollection<E>
size
public int size()Number of elements, 0 or 1.- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceSet<E>- Specified by:
sizein classAbstractCollection<E>
iterator