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.
| Modifier and Type | Field and Description |
|---|---|
| private final V | dummyValue
The dummyValue to use |
| private final Map | map
The map being used as the backing store |
| private static final long | serialVersionUID
Serialization version |
| Access | Constructor and Description |
|---|---|
| private | MapBackedSet(final Map<E, ? super V>
the map to decorate, must not be null map, final V the dummy value to use dummyValue)Constructor that wraps (not copies). |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | add(final E
element to be added to this set obj)Implements java. |
| public boolean | addAll(final Collection<? extends E>
collection containing elements to be added to this set coll)Implements java. |
| public void | clear()
Implements java. |
| public boolean | contains(final Object
element whose presence in this set is to be tested obj)Implements java. true if this set contains the specified element.
|
| public boolean | containsAll(final Collection<?>
collection to be checked for containment in this set coll)Implements java. true if this set contains all of the elements of the
specified collection.
|
| public boolean | equals(final Object
object to be compared for equality with this set obj)Overrides java. Implements java. |
| public int | hashCode()
Overrides java. Implements java. |
| public boolean | |
| public Iterator | |
| public static < the element type E, the dummy value type in the map V> MapBackedSet | Returns: a new map backed setthe map to decorate, must not be null map)Factory method to create a set from a map. |
| public static < the element type E, the dummy value type in the map V> MapBackedSet | Returns: a new map backed setthe map to decorate, must not be null map, final V the dummy value to use dummyValue)Factory method to create a set from a map. |
| public boolean | remove(final Object
object to be removed from this set, if present obj)Implements java. |
| public boolean | removeAll(final Collection<?>
collection containing elements to be removed from this set coll)Implements java. |
| public boolean | removeIf(Predicate<? super E>
a predicate which returns filter)true for elements to be
removedOverrides default java. |
| public boolean | retainAll(final Collection<?>
collection containing elements to be retained in this set coll)Implements java. |
| public int | |
| public Object[] | toArray()
Implements java. |
| public <T> T[] | toArray(final T[]
the array into which the elements of this set are to be
stored, if it is big enough; otherwise, a new array of the same
runtime type is allocated for this purpose. array)Implements java. |
| dummyValue | back to summary |
|---|---|
| private final V dummyValue The dummyValue to use | |
| map | back to summary |
|---|---|
| private final Map<E, ? super V> map The map being used as the backing store | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Serialization version | |
| MapBackedSet | back to summary |
|---|---|
| private MapBackedSet(final Map<E, ? super V> map, final V dummyValue) Constructor that wraps (not copies).
| |
| add | back to summary |
|---|---|
| public boolean add(final E obj) Implements java. Doc from java. Adds the specified element to this set if it is not already present
(optional operation). More formally, adds the specified element
The stipulation above does not imply that sets must accept all
elements; sets may refuse to add any particular element, including
| |
| addAll | back to summary |
|---|---|
| public boolean addAll(final Collection<? extends E> coll) Implements java. Doc from java. Adds all of the elements in the specified collection to this set if
they're not already present (optional operation). If the specified
collection is also a set, the
| |
| clear | back to summary |
|---|---|
| public void clear() Implements java. Doc from java. Removes all of the elements from this set (optional operation). The set will be empty after this call returns.
| |
| contains | back to summary |
|---|---|
| public boolean contains(final Object obj) Implements java. Doc from java. Returns | |
| containsAll | back to summary |
|---|---|
| public boolean containsAll(final Collection<?> coll) Implements java. Doc from java. Returns
| |
| equals | back to summary |
|---|---|
| public boolean equals(final Object obj) Overrides java. Implements java. Doc from java. Compares the specified object with this set for equality. Returns
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Implements java. Doc from java. Returns the hash code value for this set. The hash code of a set is
defined to be the sum of the hash codes of the elements in the set,
where the hash code of a
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Implements java. Doc from java. Returns
| |
| iterator | back to summary |
|---|---|
| public Iterator Implements java. Doc from java. Returns an iterator over the elements in this set. The elements are returned in no particular order (unless this set is an instance of some class that provides a guarantee). | |
| mapBackedSet | back to summary |
|---|---|
| public static <E, V> MapBackedSet Factory method to create a set from a map.
| |
| mapBackedSet | back to summary |
|---|---|
| public static <E, V> MapBackedSet Factory method to create a set from a map.
| |
| remove | back to summary |
|---|---|
| public boolean remove(final Object obj) Implements java. Doc from java. Removes the specified element from this set if it is present
(optional operation). More formally, removes an element | |
| removeAll | back to summary |
|---|---|
| public boolean removeAll(final Collection<?> coll) Implements java. Doc from java. Removes from this set all of its elements that are contained in the specified collection (optional operation). If the specified collection is also a set, this operation effectively modifies this set so that its value is the asymmetric set difference of the two sets.
| |
| removeIf | back to summary |
|---|---|
| public boolean removeIf(Predicate<? super E> filter) Overrides default java. Doc from java. Removes all of the elements of this collection that satisfy the given predicate. Errors or runtime exceptions thrown during iteration or by the predicate are relayed to the caller. | |
| retainAll | back to summary |
|---|---|
| public boolean retainAll(final Collection<?> coll) Implements java. Doc from java. Retains only the elements in this set that are contained in the specified collection (optional operation). In other words, removes from this set all of its elements that are not contained in the specified collection. If the specified collection is also a set, this operation effectively modifies this set so that its value is the intersection of the two sets.
| |
| size | back to summary |
|---|---|
| public int size() Implements java. Doc from java. Returns the number of elements in this set (its cardinality). If this
set contains more than
| |
| toArray | back to summary |
|---|---|
| public Object[] toArray() Implements java. Doc from java. Returns an array containing all of the elements in this set. If this set makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order. The returned array will be "safe" in that no references to it are maintained by this set. (In other words, this method must allocate a new array even if this set is backed by an array). The caller is thus free to modify the returned array. This method acts as bridge between array-based and collection-based APIs. | |
| toArray | back to summary |
|---|---|
| public <T> T[] toArray(final T[] array) Implements java. Doc from java. Returns an array containing all of the elements in this set; the runtime type of the returned array is that of the specified array. If the set fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this set. If this set fits in the specified array with room to spare
(i.e., the array has more elements than this set), the element in
the array immediately following the end of the set is set to
If this set makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order. Like the Suppose
String[] y = x.toArray(new String[0]);
Note that toArray(new Object[0]) is identical in function to
toArray().
| |