Class MapBackedSet<E,V>
- java.lang.Object
-
- org.apache.commons.collections4.set.MapBackedSet<E,V>
-
- Type Parameters:
E
- the type of the elements in this setV
- the dummy value type in this map
- All Implemented Interfaces:
Serializable
,Iterable<E>
,Collection<E>
,Set<E>
public final class MapBackedSet<E,V> extends Object implements Set<E>, Serializable
Decorates aMap
to obtainSet
behaviour.This class is used to create a
Set
with the same properties as the key set of any map. Thus, a ReferenceSet can be created by wrapping aReferenceMap
in an instance of this class.Most map implementation can be used to create a set by passing in dummy values. Exceptions include
BidiMap
implementations, as they require unique values.- Since:
- 3.1
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(E obj)
boolean
addAll(Collection<? extends E> coll)
void
clear()
boolean
contains(Object obj)
boolean
containsAll(Collection<?> coll)
boolean
equals(Object obj)
int
hashCode()
boolean
isEmpty()
Iterator<E>
iterator()
static <E,V>
MapBackedSet<E,V>mapBackedSet(Map<E,? super V> map)
Factory method to create a set from a map.static <E,V>
MapBackedSet<E,V>mapBackedSet(Map<E,? super V> map, V dummyValue)
Factory method to create a set from a map.boolean
remove(Object obj)
boolean
removeAll(Collection<?> coll)
boolean
retainAll(Collection<?> coll)
int
size()
Object[]
toArray()
<T> T[]
toArray(T[] array)
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.Set
spliterator
-
-
-
-
Method Detail
-
mapBackedSet
public static <E,V> MapBackedSet<E,V> mapBackedSet(Map<E,? super V> map)
Factory method to create a set from a map.- Type Parameters:
E
- the element typeV
- the dummy value type in the map- Parameters:
map
- the map to decorate, must not be null- Returns:
- a new map backed set
- Throws:
NullPointerException
- if map is null- Since:
- 4.0
-
mapBackedSet
public static <E,V> MapBackedSet<E,V> mapBackedSet(Map<E,? super V> map, V dummyValue)
Factory method to create a set from a map.- Type Parameters:
E
- the element typeV
- the dummy value type in the map- Parameters:
map
- the map to decorate, must not be nulldummyValue
- the dummy value to use- Returns:
- a new map backed set
- Throws:
NullPointerException
- if map is null- Since:
- 4.0
-
size
public int size()
-
isEmpty
public boolean isEmpty()
-
contains
public boolean contains(Object obj)
-
containsAll
public boolean containsAll(Collection<?> coll)
- Specified by:
containsAll
in interfaceCollection<E>
- Specified by:
containsAll
in interfaceSet<E>
-
add
public boolean add(E obj)
-
addAll
public boolean addAll(Collection<? extends E> coll)
-
remove
public boolean remove(Object obj)
-
removeAll
public boolean removeAll(Collection<?> coll)
-
retainAll
public boolean retainAll(Collection<?> coll)
-
clear
public void clear()
-
toArray
public Object[] toArray()
-
toArray
public <T> T[] toArray(T[] array)
-
equals
public boolean equals(Object obj)
-
-