Class MapBackedSet
- java.lang.Object
-
- org.apache.commons.collections.set.MapBackedSet
-
- All Implemented Interfaces:
Serializable
,Iterable
,Collection
,Set
public final class MapBackedSet extends Object implements Set, 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:
- Commons Collections 3.1
- Version:
- $Revision: 646777 $ $Date: 2008-04-10 14:33:15 +0200 (Thu, 10 Apr 2008) $
- Author:
- Stephen Colebourne
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Object
dummyValue
The dummyValue to useprotected Map
map
The map being used as the backing store
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(Object obj)
boolean
addAll(Collection coll)
void
clear()
boolean
contains(Object obj)
boolean
containsAll(Collection coll)
static Set
decorate(Map map)
Factory method to create a set from a map.static Set
decorate(Map map, Object dummyValue)
Factory method to create a set from a map.boolean
equals(Object obj)
int
hashCode()
boolean
isEmpty()
Iterator
iterator()
boolean
remove(Object obj)
boolean
removeAll(Collection coll)
boolean
retainAll(Collection coll)
int
size()
Object[]
toArray()
Object[]
toArray(Object[] 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
-
decorate
public static Set decorate(Map map)
Factory method to create a set from a map.- Parameters:
map
- the map to decorate, must not be null- Throws:
IllegalArgumentException
- if set is null
-
decorate
public static Set decorate(Map map, Object dummyValue)
Factory method to create a set from a map.- Parameters:
map
- the map to decorate, must not be nulldummyValue
- the dummy value to use- Throws:
IllegalArgumentException
- if map is null
-
size
public int size()
- Specified by:
size
in interfaceCollection
- Specified by:
size
in interfaceSet
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceCollection
- Specified by:
isEmpty
in interfaceSet
-
iterator
public Iterator iterator()
-
contains
public boolean contains(Object obj)
- Specified by:
contains
in interfaceCollection
- Specified by:
contains
in interfaceSet
-
containsAll
public boolean containsAll(Collection coll)
- Specified by:
containsAll
in interfaceCollection
- Specified by:
containsAll
in interfaceSet
-
add
public boolean add(Object obj)
- Specified by:
add
in interfaceCollection
- Specified by:
add
in interfaceSet
-
addAll
public boolean addAll(Collection coll)
- Specified by:
addAll
in interfaceCollection
- Specified by:
addAll
in interfaceSet
-
remove
public boolean remove(Object obj)
- Specified by:
remove
in interfaceCollection
- Specified by:
remove
in interfaceSet
-
removeAll
public boolean removeAll(Collection coll)
- Specified by:
removeAll
in interfaceCollection
- Specified by:
removeAll
in interfaceSet
-
retainAll
public boolean retainAll(Collection coll)
- Specified by:
retainAll
in interfaceCollection
- Specified by:
retainAll
in interfaceSet
-
clear
public void clear()
- Specified by:
clear
in interfaceCollection
- Specified by:
clear
in interfaceSet
-
toArray
public Object[] toArray()
- Specified by:
toArray
in interfaceCollection
- Specified by:
toArray
in interfaceSet
-
toArray
public Object[] toArray(Object[] array)
- Specified by:
toArray
in interfaceCollection
- Specified by:
toArray
in interfaceSet
-
equals
public boolean equals(Object obj)
-
-