Class ConcurrentHashMap.KeySetView<K,V>
- All Implemented Interfaces:
Serializable, Iterable<K>, Collection<K>, Set<K>
- Enclosing class:
ConcurrentHashMap<K,V>
java.util.concurrent.ConcurrentHashMap.KeySetView: the keys of a
map as a set. A view created with a mapped value (keySet(V),
newKeySet()) also accepts add, which maps the key to that value.- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbooleanAttempts to addobjectto the contents of thisCollection(optional).booleanaddAll(Collection<? extends K> c) Attempts to add all of the objects contained incollectionto the contents of thisCollection(optional).voidclear()Removes all elements from thisCollection, leaving it empty (optional).booleanTests whether thisCollectioncontains the specified object.getMap()The map this is a view of.booleanisEmpty()Returns if thisCollectioncontains no elements.iterator()Returns an instance ofIteratorthat may be used to access the objects contained by thisCollection.booleanRemoves one instance of the specified object from thisCollectionif one is contained (optional).intsize()Returns a count of how many objects thisCollectioncontains.Methods inherited from class AbstractSet
equals, hashCode, removeAllMethods inherited from class AbstractCollection
containsAll, retainAll, toArray, toArray, toStringMethods inherited from interface Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface Set
containsAll, retainAll, spliterator, toArray, toArray
-
Method Details
-
getMap
The map this is a view of. It is the live map, as in the JDK: the view exists to share it. -
getMappedValue
-
iterator
Description copied from class:AbstractCollectionReturns an instance of
Iteratorthat may be used to access the objects contained by thisCollection. The order in which the elements are returned by theIteratoris not defined unless the instance of theCollectionhas a defined order. In that case, the elements are returned in that order.In this class this method is declared abstract and has to be implemented by concrete
Collectionimplementations.Returns
an iterator for accessing the
Collectioncontents. -
size
public int size()Description copied from class:AbstractCollectionReturns a count of how many objects this
Collectioncontains.In this class this method is declared abstract and has to be implemented by concrete
Collectionimplementations.Returns
- Specified by:
sizein interfaceCollection<K>- Specified by:
sizein interfaceSet<K>- Specified by:
sizein classAbstractCollection<K>- Returns:
- how many objects this
Collectioncontains, orInteger.MAX_VALUEif there are more thanInteger.MAX_VALUEelements in thisCollection.
-
isEmpty
public boolean isEmpty()Description copied from class:AbstractCollectionReturns if this
Collectioncontains no elements. This implementation tests, whethersizereturns 0.Returns
- Specified by:
isEmptyin interfaceCollection<K>- Specified by:
isEmptyin interfaceSet<K>- Overrides:
isEmptyin classAbstractCollection<K>- Returns:
trueif thisCollectionhas no elements,falseotherwise.See also
- #size
-
contains
Description copied from class:AbstractCollectionTests whether this
Collectioncontains the specified object. This implementation iterates over thisCollectionand tests, whether any element is equal to the given object. Ifobject != nullthenobject.equals(e)is called for each elementereturned by the iterator until the element is found. Ifobject == nullthen each elementereturned by the iterator is compared with the teste == null.Parameters
object: the object to search for.
Returns
trueif object is an element of thisCollection,falseotherwise.Throws
-
ClassCastException: if the object to look for isn't of the correct type. -
NullPointerException: @throws NullPointerException if the object to look for isnulland thisCollectiondoesn't supportnullelements.
- Specified by:
containsin interfaceCollection<K>- Specified by:
containsin interfaceSet<K>- Overrides:
containsin classAbstractCollection<K>- Returns:
trueif object is an element of thisCollection,falseotherwise.Throws
-
ClassCastException: @throws ClassCastException if the object to look for isn't of the correct type. -
NullPointerException: @throws NullPointerException if the object to look for isnulland thisCollectiondoesn't supportnullelements.
-
-
remove
Description copied from class:AbstractCollectionRemoves one instance of the specified object from this
Collectionif one is contained (optional). This implementation iterates over thisCollectionand tests for each elementereturned by the iterator, whethereis equal to the given object. Ifobject != nullthen this test is performed usingobject.equals(e), otherwise usingobject == null. If an element equal to the given object is found, then theremovemethod is called on the iterator andtrueis returned,falseotherwise. If the iterator does not support removing elements, anUnsupportedOperationExceptionis thrown.Parameters
object: the object to remove.
Returns
- Specified by:
removein interfaceCollection<K>- Specified by:
removein interfaceSet<K>- Overrides:
removein classAbstractCollection<K>- Returns:
trueif thisCollectionis modified,falseotherwise.Throws
-
UnsupportedOperationException: if removing from thisCollectionis not supported. -
ClassCastException: if the object passed is not of the correct type. -
NullPointerException: @throws NullPointerException ifobjectisnulland thisCollectiondoesn't supportnullelements.
-
-
clear
public void clear()Description copied from class:AbstractCollectionRemoves all elements from this
Collection, leaving it empty (optional). This implementation iterates over thisCollectionand calls theremovemethod on each element. If the iterator does not support removal of elements, anUnsupportedOperationExceptionis thrown.Concrete implementations usually can clear a
Collectionmore efficiently and should therefore overwrite this method.Throws
UnsupportedOperationException: @throws UnsupportedOperationException it the iterator does not support removing elements from thisCollection
See also
-
#iterator
-
#isEmpty
-
#size
- Specified by:
clearin interfaceCollection<K>- Specified by:
clearin interfaceSet<K>- Overrides:
clearin classAbstractCollection<K>
-
add
Description copied from interface:CollectionAttempts to add
objectto the contents of thisCollection(optional).After this method finishes successfully it is guaranteed that the object is contained in the collection.
If the collection was modified it returns
true,falseif no changes were made.An implementation of
Collectionmay narrow the set of accepted objects, but it has to specify this in the documentation. If the object to be added does not meet this restriction, then anIllegalArgumentExceptionis thrown.If a collection does not yet contain an object that is to be added and adding the object fails, this method must throw an appropriate unchecked Exception. Returning false is not permitted in this case because it would violate the postcondition that the element will be part of the collection after this method finishes.
Parameters
object: the object to add.
Returns
- Specified by:
addin interfaceCollection<K>- Specified by:
addin interfaceSet<K>- Overrides:
addin classAbstractCollection<K>- Returns:
trueif thisCollectionis modified,falseotherwise.Throws
-
UnsupportedOperationException: if adding to thisCollectionis not supported. -
ClassCastException: @throws ClassCastException if the class of the object is inappropriate for this collection. -
IllegalArgumentException: if the object cannot be added to thisCollection. -
NullPointerException: if null elements cannot be added to theCollection.
-
-
addAll
Description copied from class:AbstractCollectionAttempts to add all of the objects contained in
collectionto the contents of thisCollection(optional). This implementation iterates over the givenCollectionand callsaddfor each element. If any of these calls returntrue, thentrueis returned as result of this method call,falseotherwise. If thisCollectiondoes not support adding elements, anUnsupportedOperationExceptionis thrown.If the passed
Collectionis changed during the process of adding elements to thisCollection, the behavior depends on the behavior of the passedCollection.Parameters
collection: the collection of objects.
Returns
- Specified by:
addAllin interfaceCollection<K>- Specified by:
addAllin interfaceSet<K>- Overrides:
addAllin classAbstractCollection<K>- Returns:
trueif thisCollectionis modified,falseotherwise.Throws
-
UnsupportedOperationException: if adding to thisCollectionis not supported. -
ClassCastException: @throws ClassCastException if the class of an object is inappropriate for thisCollection. -
IllegalArgumentException: if an object cannot be added to thisCollection. -
NullPointerException: @throws NullPointerException ifcollectionisnull, or if it containsnullelements and thisCollectiondoes not support such elements.
-
-