public static class ConcurrentHashMap.KeySetView<K,V> extends Object implements Set<K>, Serializable
Set of keys, in
which additions may optionally be enabled by mapping to a
common value. This class cannot be directly instantiated.
See keySet(),
keySet(V),
newKeySet(),
newKeySet(int).| Modifier and Type | Method and Description |
|---|---|
boolean |
add(K e)
Adds the specified key to this set view by mapping the key to
the default mapped value in the backing map, if defined.
|
boolean |
addAll(Collection<? extends K> c)
Adds all of the elements in the specified collection to this set,
as if by calling
add(K) on each one. |
void |
clear()
Removes all of the elements from this view, by removing all
the mappings from the map backing this view.
|
boolean |
contains(Object o)
Returns true if this collection contains the specified element.
|
boolean |
containsAll(Collection<?> c)
Returns true if this collection contains all of the elements
in the specified collection.
|
boolean |
equals(Object o)
Compares this instance with the specified object and indicates if they
are equal.
|
void |
forEach(Consumer<? super K> action)
Performs the given action for each element of the
Iterable
until all elements have been processed or the action throws an
exception. |
ConcurrentHashMap<K,V> |
getMap()
Returns the map backing this view.
|
V |
getMappedValue()
Returns the default mapped value for additions,
or
null if additions are not supported. |
int |
hashCode()
Returns an integer hash code for this object.
|
boolean |
isEmpty()
Returns true if this collection contains no elements.
|
Iterator<K> |
iterator()
Returns an iterator over the elements in this collection.
|
boolean |
remove(Object o)
Removes the key from this map view, by removing the key (and its
corresponding value) from the backing map.
|
boolean |
removeAll(Collection<?> c)
Removes all of this collection's elements that are also contained in the
specified collection (optional operation).
|
boolean |
retainAll(Collection<?> c)
Retains only the elements in this collection that are contained in the
specified collection (optional operation).
|
int |
size()
Returns the number of elements in this collection.
|
Spliterator<K> |
spliterator()
Creates a
Spliterator over the elements in this set. |
Object[] |
toArray()
Returns an array containing all of the elements in this collection.
|
<T> T[] |
toArray(T[] a)
Returns an array containing all of the elements in this collection;
the runtime type of the returned array is that of the specified array.
|
String |
toString()
Returns a string representation of this collection.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, waitclear, containsAll, copyOf, isEmpty, of, of, of, of, of, of, of, of, of, of, of, of, removeAll, retainAll, size, toArray, toArrayparallelStream, removeIf, stream, toArraypublic V getMappedValue()
null if additions are not supported.null
if not supportedpublic boolean contains(Object o)
contains in interface Collection<K>contains in interface Set<K>o - element whose presence in this collection is to be testedNullPointerException - if the specified key is nullpublic boolean remove(Object o)
remove in interface Collection<K>remove in interface Set<K>o - the key to be removed from the backing maptrue if the backing map contained the specified keyNullPointerException - if the specified key is nullpublic Iterator<K> iterator()
The returned iterator is weakly consistent.
public boolean add(K e)
add in interface Collection<K>add in interface Set<K>e - key to be addedtrue if this set changed as a result of the callNullPointerException - if the specified key is nullUnsupportedOperationException - if no default mapped value
for additions was providedpublic boolean addAll(Collection<? extends K> c)
add(K) on each one.addAll in interface Collection<K>addAll in interface Set<K>c - the elements to be inserted into this settrue if this set changed as a result of the callNullPointerException - if the collection or any of its
elements are nullUnsupportedOperationException - if no default mapped value
for additions was providedSet.add(Object)public int hashCode()
ObjectObject.equals(java.lang.Object) returns true must return
the same hash code value. This means that subclasses of Object
usually override both methods or neither method.
Note that hash values must not change over time unless information used in equals comparisons also changes.
See Writing a correct
hashCode method
if you intend implementing your own hashCode method.
hashCode in interface Collection<K>hashCode in interface Set<K>hashCode in class ObjectObject.equals(java.lang.Object)public boolean equals(Object o)
Objecto must represent the same object
as this instance using a class-specific comparison. The general contract
is that this comparison should be reflexive, symmetric, and transitive.
Also, no object reference other than null is equal to null.
The default implementation returns true only if this ==
o. See Writing a correct
equals method
if you intend implementing your own equals method.
The general contract for the equals and Object.hashCode() methods is that if equals returns true for
any two objects, then hashCode() must return the same value for
these objects. This means that subclasses of Object usually
override either both methods or neither of them.
equals in interface Collection<K>equals in interface Set<K>equals in class Objecto - the object to compare this instance with.true if the specified object is equal to this Object; false otherwise.Object.hashCode()public Spliterator<K> spliterator()
SetSpliterator over the elements in this set.
The Spliterator reports Spliterator.DISTINCT.
Implementations should document the reporting of additional
characteristic values.
spliterator in interface Iterable<K>spliterator in interface Collection<K>spliterator in interface Set<K>Spliterator over the elements in this setpublic void forEach(Consumer<? super K> action)
CollectionIterable
until all elements have been processed or the action throws an
exception. Unless otherwise specified by the implementing class,
actions are performed in the order of iteration (if an iteration order
is specified). Exceptions thrown by the action are relayed to the
caller.public ConcurrentHashMap<K,V> getMap()
public final void clear()
clear in interface Collection<E>public final int size()
Collectionsize in interface Collection<E>public final boolean isEmpty()
CollectionisEmpty in interface Collection<E>public final Object[] toArray()
CollectionThe returned array will be "safe" in that no references to it are maintained by this collection. (In other words, this method must allocate a new array even if this collection 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 in interface Collection<E>public final <T> T[] toArray(T[] a)
CollectionIf this collection fits in the specified array with room to spare (i.e., the array has more elements than this collection), the element in the array immediately following the end of the collection is set to null. (This is useful in determining the length of this collection only if the caller knows that this collection does not contain any null elements.)
If this collection 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 Collection.toArray() method, this method acts as bridge between
array-based and collection-based APIs. Further, this method allows
precise control over the runtime type of the output array, and may,
under certain circumstances, be used to save allocation costs.
Suppose x is a collection known to contain only strings. The following code can be used to dump the collection into a newly allocated array of String:
String[] y = x.toArray(new String[0]);
Note that toArray(new Object[0]) is identical in function to
toArray().toArray in interface Collection<E>T - the runtime type of the array to contain the collectiona - the array into which the elements of this collection are to be
stored, if it is big enough; otherwise, a new array of the same
runtime type is allocated for this purpose.public final String toString()
"[]").
Adjacent elements are separated by the characters ", "
(comma and space). Elements are converted to strings as by
String.valueOf(Object).public final boolean containsAll(Collection<?> c)
CollectioncontainsAll in interface Collection<E>c - collection to be checked for containment in this collectionCollection.contains(Object)public boolean removeAll(Collection<?> c)
CollectionremoveAll in interface Collection<E>c - collection containing elements to be removed from this collectionCollection.remove(Object),
Collection.contains(Object)public final boolean retainAll(Collection<?> c)
CollectionretainAll in interface Collection<E>c - collection containing elements to be retained in this collectionCollection.remove(Object),
Collection.contains(Object)