java.lang.Object
java.util.concurrent.ConcurrentHashMap.KeySetView<K,V>
- All Implemented Interfaces:
Serializable
,Iterable<K>
,Collection<K>
,Set<K>
- Enclosing class:
ConcurrentHashMap<K,
V>
public static class ConcurrentHashMap.KeySetView<K,V>
extends Object
implements Set<K>, Serializable
A view of a ConcurrentHashMap as a
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)
.- Since:
- 1.8
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionboolean
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 callingadd(K)
on each one.final void
clear()
Removes all of the elements from this view, by removing all the mappings from the map backing this view.boolean
final boolean
containsAll
(Collection<?> c) boolean
getMap()
Returns the map backing this view.Returns the default mapped value for additions, ornull
if additions are not supported.int
hashCode()
final boolean
isEmpty()
iterator()
Returns an iterator over the elements in this collection.boolean
Removes the key from this map view, by removing the key (and its corresponding value) from the backing map.boolean
removeAll
(Collection<?> c) final boolean
retainAll
(Collection<?> c) final int
size()
final Object[]
toArray()
final <T> T[]
toArray
(T[] a) final String
toString()
Returns a string representation of this collection.Methods declared in class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods declared in interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods declared in interface java.util.Set
clear, containsAll, isEmpty, removeAll, retainAll, size, spliterator, toArray, toArray
-
Method Details
-
getMappedValue
Returns the default mapped value for additions, ornull
if additions are not supported.- Returns:
- the default mapped value for additions, or
null
if not supported
-
contains
- Specified by:
contains
in interfaceCollection<K>
- Specified by:
contains
in interfaceSet<K>
- Throws:
NullPointerException
- if the specified key is null
-
remove
Removes the key from this map view, by removing the key (and its corresponding value) from the backing map. This method does nothing if the key is not in the map.- Specified by:
remove
in interfaceCollection<K>
- Specified by:
remove
in interfaceSet<K>
- Parameters:
o
- the key to be removed from the backing map- Returns:
true
if the backing map contained the specified key- Throws:
NullPointerException
- if the specified key is null
-
iterator
Returns an iterator over the elements in this collection.The returned iterator is weakly consistent.
-
add
Adds the specified key to this set view by mapping the key to the default mapped value in the backing map, if defined.- Specified by:
add
in interfaceCollection<K>
- Specified by:
add
in interfaceSet<K>
- Parameters:
e
- key to be added- Returns:
true
if this set changed as a result of the call- Throws:
NullPointerException
- if the specified key is nullUnsupportedOperationException
- if no default mapped value for additions was provided
-
addAll
Adds all of the elements in the specified collection to this set, as if by callingadd(K)
on each one.- Specified by:
addAll
in interfaceCollection<K>
- Specified by:
addAll
in interfaceSet<K>
- Parameters:
c
- the elements to be inserted into this set- Returns:
true
if this set changed as a result of the call- Throws:
NullPointerException
- if the collection or any of its elements arenull
UnsupportedOperationException
- if no default mapped value for additions was provided
-
hashCode
public int hashCode() -
equals
-
getMap
Returns the map backing this view.- Returns:
- the map backing this view
-
clear
public final void clear()Removes all of the elements from this view, by removing all the mappings from the map backing this view.- Specified by:
clear
in interfaceCollection<K>
-
size
public final int size()- Specified by:
size
in interfaceCollection<K>
-
isEmpty
public final boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<K>
-
toArray
- Specified by:
toArray
in interfaceCollection<K>
-
toArray
public final <T> T[] toArray(T[] a) - Specified by:
toArray
in interfaceCollection<K>
-
toString
Returns a string representation of this collection. The string representation consists of the string representations of the collection's elements in the order they are returned by its iterator, enclosed in square brackets ("[]"
). Adjacent elements are separated by the characters", "
(comma and space). Elements are converted to strings as byString.valueOf(Object)
. -
containsAll
- Specified by:
containsAll
in interfaceCollection<K>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<K>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<K>
-