org.apache.commons.collections.set
Class MapBackedSet<K,V>

java.lang.Object
  extended by org.apache.commons.collections.set.MapBackedSet<K,V>
All Implemented Interfaces:
Serializable, Iterable<K>, Collection<K>, Set<K>

public final class MapBackedSet<K,V>
extends Object
implements Set<K>, Serializable

Decorates a Map to obtain Set 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 a ReferenceMap 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: 1.1.1.1 $ $Date: 2005/05/23 04:36:21 $
Author:
Matt Hall, John Watkinson, Stephen Colebourne
See Also:
Serialized Form

Field Summary
protected  V dummyValue
          The dummyValue to use
protected  Map<K,V> map
          The map being used as the backing store
 
Method Summary
 boolean add(K obj)
           
 boolean addAll(Collection<? extends K> coll)
           
 void clear()
           
 boolean contains(Object obj)
           
 boolean containsAll(Collection<?> coll)
           
static
<K,V> Set<K>
decorate(Map<K,V> map)
          Factory method to create a set from a map.
static
<K,V> Set<K>
decorate(Map<K,V> map, V dummyValue)
          Factory method to create a set from a map.
 boolean equals(Object obj)
           
 int hashCode()
           
 boolean isEmpty()
           
 Iterator<K> iterator()
           
 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
 

Field Detail

map

protected final Map<K,V> map
The map being used as the backing store


dummyValue

protected final V dummyValue
The dummyValue to use

Method Detail

decorate

public static <K,V> Set<K> decorate(Map<K,V> 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 <K,V> Set<K> decorate(Map<K,V> map,
                                    V dummyValue)
Factory method to create a set from a map.

Parameters:
map - the map to decorate, must not be null
dummyValue - the dummy value to use
Throws:
IllegalArgumentException - if map is null

size

public int size()
Specified by:
size in interface Collection<K>
Specified by:
size in interface Set<K>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<K>
Specified by:
isEmpty in interface Set<K>

iterator

public Iterator<K> iterator()
Specified by:
iterator in interface Iterable<K>
Specified by:
iterator in interface Collection<K>
Specified by:
iterator in interface Set<K>

contains

public boolean contains(Object obj)
Specified by:
contains in interface Collection<K>
Specified by:
contains in interface Set<K>

containsAll

public boolean containsAll(Collection<?> coll)
Specified by:
containsAll in interface Collection<K>
Specified by:
containsAll in interface Set<K>

add

public boolean add(K obj)
Specified by:
add in interface Collection<K>
Specified by:
add in interface Set<K>

addAll

public boolean addAll(Collection<? extends K> coll)
Specified by:
addAll in interface Collection<K>
Specified by:
addAll in interface Set<K>

remove

public boolean remove(Object obj)
Specified by:
remove in interface Collection<K>
Specified by:
remove in interface Set<K>

removeAll

public boolean removeAll(Collection<?> coll)
Specified by:
removeAll in interface Collection<K>
Specified by:
removeAll in interface Set<K>

retainAll

public boolean retainAll(Collection<?> coll)
Specified by:
retainAll in interface Collection<K>
Specified by:
retainAll in interface Set<K>

clear

public void clear()
Specified by:
clear in interface Collection<K>
Specified by:
clear in interface Set<K>

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection<K>
Specified by:
toArray in interface Set<K>

toArray

public <T> T[] toArray(T[] array)
Specified by:
toArray in interface Collection<K>
Specified by:
toArray in interface Set<K>

equals

public boolean equals(Object obj)
Specified by:
equals in interface Collection<K>
Specified by:
equals in interface Set<K>
Overrides:
equals in class Object

hashCode

public int hashCode()
Specified by:
hashCode in interface Collection<K>
Specified by:
hashCode in interface Set<K>
Overrides:
hashCode in class Object


Copyright © 2005-2005 Apache Software Foundation, Matt Hall, John Watkinson. All Rights Reserved.