com.senn.magic.collections
Class GeneralSetFromMap<S>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<S>
com.senn.magic.collections.GeneralSetFromMap<S>
- Type Parameters:
S
- the class of the objects in the set
- All Implemented Interfaces:
- Iterable<S>, Collection<S>, Set<S>
- Direct Known Subclasses:
- ConcurrentHashSet, IdentityHashSet, WeakHashSet
public class GeneralSetFromMap<S>
- extends AbstractSet<S>
- implements Set<S>
General superclass for any custom Set
-implementation based on a Map
.
In Java 6 this has been put into a single method:
Collections.newSetFromMap(Map<S, Boolean>)
This class (and its subclasses) is basicly a wrapper for the same functionality.
Assuming you want to create a custom Set
-impl for your custom Map
, you
have to do the following:
- create a custom constructor
- let it call the super-constructor from GeneralSetFromMap with an empty impl of your custom Map
public class MyCustomSet<S> extends GeneralSetFromMap<S> implements Set<S>
{
public MyCustomSet()
{
super(new MyCustomMap<S, Object>());
}
}
- Since:
- 3.3
- Author:
- Bart Thierens
Last modification: 02/06/2010
Field Summary |
protected Set<S> |
set
the internal Set object |
set
protected Set<S> set
- the internal
Set
object
GeneralSetFromMap
public GeneralSetFromMap(Map<S,?> map)
- Constructor that builds the set from a
Map
.
- Parameters:
map
- the map implementation
add
public boolean add(S o)
- Specified by:
add
in interface Collection<S>
- Specified by:
add
in interface Set<S>
- Overrides:
add
in class AbstractCollection<S>
- Parameters:
o
-
- Returns:
- See Also:
Set.add(java.lang.Object)
addAll
public boolean addAll(Collection<? extends S> c)
- Specified by:
addAll
in interface Collection<S>
- Specified by:
addAll
in interface Set<S>
- Overrides:
addAll
in class AbstractCollection<S>
- Parameters:
c
-
- Returns:
- See Also:
Set.addAll(java.util.Collection)
clear
public void clear()
- Specified by:
clear
in interface Collection<S>
- Specified by:
clear
in interface Set<S>
- Overrides:
clear
in class AbstractCollection<S>
- See Also:
Set.clear()
contains
public boolean contains(Object o)
- Specified by:
contains
in interface Collection<S>
- Specified by:
contains
in interface Set<S>
- Overrides:
contains
in class AbstractCollection<S>
- Parameters:
o
-
- Returns:
- See Also:
Set.contains(java.lang.Object)
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
containsAll
in interface Collection<S>
- Specified by:
containsAll
in interface Set<S>
- Overrides:
containsAll
in class AbstractCollection<S>
- Parameters:
c
-
- Returns:
- See Also:
Set.containsAll(java.util.Collection)
equals
public boolean equals(Object o)
- Specified by:
equals
in interface Collection<S>
- Specified by:
equals
in interface Set<S>
- Overrides:
equals
in class AbstractSet<S>
- Parameters:
o
-
- Returns:
- See Also:
Set.equals(java.lang.Object)
hashCode
public int hashCode()
- Specified by:
hashCode
in interface Collection<S>
- Specified by:
hashCode
in interface Set<S>
- Overrides:
hashCode
in class AbstractSet<S>
- Returns:
- See Also:
Set.hashCode()
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interface Collection<S>
- Specified by:
isEmpty
in interface Set<S>
- Overrides:
isEmpty
in class AbstractCollection<S>
- Returns:
- See Also:
Set.isEmpty()
iterator
public Iterator<S> iterator()
- Specified by:
iterator
in interface Iterable<S>
- Specified by:
iterator
in interface Collection<S>
- Specified by:
iterator
in interface Set<S>
- Specified by:
iterator
in class AbstractCollection<S>
- Returns:
- See Also:
Set.iterator()
remove
public boolean remove(Object o)
- Specified by:
remove
in interface Collection<S>
- Specified by:
remove
in interface Set<S>
- Overrides:
remove
in class AbstractCollection<S>
- Parameters:
o
-
- Returns:
- See Also:
Set.remove(java.lang.Object)
removeAll
public boolean removeAll(Collection<?> c)
- Specified by:
removeAll
in interface Collection<S>
- Specified by:
removeAll
in interface Set<S>
- Overrides:
removeAll
in class AbstractSet<S>
- Parameters:
c
-
- Returns:
- See Also:
Set.removeAll(java.util.Collection)
retainAll
public boolean retainAll(Collection<?> c)
- Specified by:
retainAll
in interface Collection<S>
- Specified by:
retainAll
in interface Set<S>
- Overrides:
retainAll
in class AbstractCollection<S>
- Parameters:
c
-
- Returns:
- See Also:
Set.retainAll(java.util.Collection)
size
public int size()
- Specified by:
size
in interface Collection<S>
- Specified by:
size
in interface Set<S>
- Specified by:
size
in class AbstractCollection<S>
- Returns:
- See Also:
Set.size()
toArray
public Object[] toArray()
- Specified by:
toArray
in interface Collection<S>
- Specified by:
toArray
in interface Set<S>
- Overrides:
toArray
in class AbstractCollection<S>
- Returns:
- See Also:
Set.toArray()
toArray
public <T> T[] toArray(T[] a)
- Specified by:
toArray
in interface Collection<S>
- Specified by:
toArray
in interface Set<S>
- Overrides:
toArray
in class AbstractCollection<S>
- Type Parameters:
T
- - Parameters:
a
-
- Returns:
- See Also:
java.util.Set#toArray(T[])
getImplClass
public Class<?> getImplClass()
- Returns the class of the current
Set
-implementation
- Returns:
Class
- the class of the Set
impl