KeySetView
class KeySetView<K : Any!, V : Any!> : MutableCollection<K>, Serializable, MutableSet<K>
| kotlin.Any | |
| ↳ | java.util.concurrent.ConcurrentHashMap.KeySetView |
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(V), newKeySet(), newKeySet(int).
Summary
| Public methods | |
|---|---|
| Boolean |
add(element: K)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(elements: Collection<K>)Adds all of the elements in the specified collection to this set, as if by calling |
| Unit |
clear()Removes all of the elements from this view, by removing all the mappings from the map backing this view. |
| Boolean |
contains(element: K)Returns |
| Boolean |
containsAll(elements: Collection<K>)Returns |
| Boolean |
Indicates whether some other object is "equal to" this one. |
| Unit |
Performs the given action for each element of the |
| ConcurrentHashMap<K, V> |
getMap()Returns the map backing this view. |
| V? |
Returns the default mapped value for additions, or |
| Int |
hashCode()Returns a hash code value for the object. |
| Boolean |
isEmpty()Returns |
| MutableIterator<K> |
iterator() |
| Boolean |
remove(element: K)Removes the key from this map view, by removing the key (and its corresponding value) from the backing map. |
| Boolean |
removeAll(elements: Collection<K>)Removes all of this collection's elements that are also contained in the specified collection (optional operation). |
| Boolean |
retainAll(elements: Collection<K>)Retains only the elements in this collection that are contained in the specified collection (optional operation). |
| Spliterator<K> |
Creates a |
| Array<Any!> |
toArray()Returns an array containing all of the elements in this collection. |
| Array<T> |
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. |
| Properties | |
|---|---|
| Int |
Returns the number of elements in this collection. |
Public methods
add
fun add(element: K): Boolean
Adds the specified key to this set view by mapping the key to the default mapped value in the backing map, if defined.
| Parameters | |
|---|---|
e |
key to be added |
| Return | |
|---|---|
Boolean |
true if this set changed as a result of the call |
| Exceptions | |
|---|---|
java.lang.ClassCastException |
if the class of the specified element prevents it from being added to this set |
java.lang.IllegalArgumentException |
if some property of the specified element prevents it from being added to this set |
java.lang.IllegalStateException |
if the element cannot be added at this time due to insertion restrictions |
java.lang.NullPointerException |
if the specified key is null |
java.lang.UnsupportedOperationException |
if no default mapped value for additions was provided |
addAll
fun addAll(elements: Collection<K>): Boolean
Adds all of the elements in the specified collection to this set, as if by calling add on each one.
| Parameters | |
|---|---|
c |
the elements to be inserted into this set |
| Return | |
|---|---|
Boolean |
true if this set changed as a result of the call |
| Exceptions | |
|---|---|
java.lang.ClassCastException |
if the class of an element of the specified collection prevents it from being added to this set |
java.lang.IllegalArgumentException |
if some property of an element of the specified collection prevents it from being added to this set |
java.lang.IllegalStateException |
if not all the elements can be added at this time due to insertion restrictions |
java.lang.NullPointerException |
if the collection or any of its elements are null |
java.lang.UnsupportedOperationException |
if no default mapped value for additions was provided |
clear
fun clear(): Unit
Removes all of the elements from this view, by removing all the mappings from the map backing this view.
| Exceptions | |
|---|---|
java.lang.UnsupportedOperationException |
if the clear method is not supported by this set |
contains
fun contains(element: K): Boolean
Returns true if this collection contains the specified element. More formally, returns true if and only if this collection contains at least one element e such that Objects.equals(o, e).
| Parameters | |
|---|---|
o |
element whose presence in this set is to be tested |
| Return | |
|---|---|
Boolean |
true if this set contains the specified element |
| Exceptions | |
|---|---|
java.lang.ClassCastException |
if the type of the specified element is incompatible with this set (optional) |
java.lang.NullPointerException |
if the specified key is null |
containsAll
fun containsAll(elements: Collection<K>): Boolean
Returns true if this collection contains all of the elements in the specified collection.
| Parameters | |
|---|---|
c |
collection to be checked for containment in this set |
| Return | |
|---|---|
Boolean |
true if this set contains all of the elements of the specified collection |
| Exceptions | |
|---|---|
java.lang.ClassCastException |
if the types of one or more elements in the specified collection are incompatible with this set (optional) |
java.lang.NullPointerException |
if the specified collection contains one or more null elements and this set does not permit null elements (optional), or if the specified collection is null |
equals
fun equals(other: Any?): Boolean
Indicates whether some other object is "equal to" this one.
The equals method implements an equivalence relation on non-null object references:
- It is reflexive: for any non-null reference value
x,x.equals(x)should returntrue. - It is symmetric: for any non-null reference values
xandy,x.equals(y)should returntrueif and only ify.equals(x)returnstrue. - It is transitive: for any non-null reference values
x,y, andz, ifx.equals(y)returnstrueandy.equals(z)returnstrue, thenx.equals(z)should returntrue. - It is consistent: for any non-null reference values
xandy, multiple invocations ofx.equals(y)consistently returntrueor consistently returnfalse, provided no information used inequalscomparisons on the objects is modified. - For any non-null reference value
x,x.equals(null)should returnfalse.
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.
| Parameters | |
|---|---|
obj |
the reference object with which to compare. |
o |
object to be compared for equality with this set |
| Return | |
|---|---|
Boolean |
true if the specified object is equal to this set |
forEach
fun forEach(action: Consumer<in K>): Unit
Performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception. Actions are performed in the order of iteration, if that order is specified. Exceptions thrown by the action are relayed to the caller.
The behavior of this method is unspecified if the action performs side-effects that modify the underlying source of elements, unless an overriding class has specified a concurrent modification policy.
| Parameters | |
|---|---|
action |
Consumer<in K>: The action to be performed for each element |
| Exceptions | |
|---|---|
java.lang.NullPointerException |
if the specified action is null |
getMap
fun getMap(): ConcurrentHashMap<K, V>
Returns the map backing this view.
| Return | |
|---|---|
ConcurrentHashMap<K, V> |
the map backing this view |
getMappedValue
fun getMappedValue(): V?
Returns the default mapped value for additions, or null if additions are not supported.
| Return | |
|---|---|
V? |
the default mapped value for additions, or null if not supported |
hashCode
fun hashCode(): Int
Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.
The general contract of hashCode is:
- Whenever it is invoked on the same object more than once during an execution of a Java application, the
hashCodemethod must consistently return the same integer, provided no information used inequalscomparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. - If two objects are equal according to the
equalsmethod, then calling thehashCodemethod on each of the two objects must produce the same integer result. - It is not required that if two objects are unequal according to the
equalsmethod, then calling thehashCodemethod on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
| Return | |
|---|---|
Int |
the hash code value for this set |
isEmpty
fun isEmpty(): Boolean
Returns true if this collection contains no elements.
| Return | |
|---|---|
Boolean |
true if this set contains no elements |
iterator
fun iterator(): MutableIterator<K>
| Return | |
|---|---|
MutableIterator<K> |
an iterator over the keys of the backing map |
remove
fun remove(element: K): Boolean
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.
| Parameters | |
|---|---|
o |
the key to be removed from the backing map |
| Return | |
|---|---|
Boolean |
true if the backing map contained the specified key |
| Exceptions | |
|---|---|
java.lang.ClassCastException |
if the type of the specified element is incompatible with this set (optional) |
java.lang.NullPointerException |
if the specified key is null |
java.lang.UnsupportedOperationException |
if the remove operation is not supported by this set |
removeAll
fun removeAll(elements: Collection<K>): Boolean
Removes all of this collection's elements that are also contained in the specified collection (optional operation). After this call returns, this collection will contain no elements in common with the specified collection.
| Parameters | |
|---|---|
c |
collection containing elements to be removed from this set |
| Return | |
|---|---|
Boolean |
true if this set changed as a result of the call |
| Exceptions | |
|---|---|
java.lang.ClassCastException |
if the class of an element of this set is incompatible with the specified collection (optional) |
java.lang.NullPointerException |
if this set contains a null element and the specified collection does not permit null elements (optional), or if the specified collection is null |
java.lang.UnsupportedOperationException |
if the removeAll operation is not supported by this set |
retainAll
fun retainAll(elements: Collection<K>): Boolean
Retains only the elements in this collection that are contained in the specified collection (optional operation). In other words, removes from this collection all of its elements that are not contained in the specified collection.
| Parameters | |
|---|---|
c |
collection containing elements to be retained in this set |
| Return | |
|---|---|
Boolean |
true if this set changed as a result of the call |
| Exceptions | |
|---|---|
java.lang.ClassCastException |
if the class of an element of this set is incompatible with the specified collection (optional) |
java.lang.NullPointerException |
if this set contains a null element and the specified collection does not permit null elements (optional), or if the specified collection is null |
java.lang.UnsupportedOperationException |
if the retainAll operation is not supported by this set |
spliterator
fun spliterator(): Spliterator<K>
Creates a Spliterator over the elements in this collection. Implementations should document characteristic values reported by the spliterator. Such characteristic values are not required to be reported if the spliterator reports Spliterator.SIZED and this collection contains no elements.
The default implementation should be overridden by subclasses that can return a more efficient spliterator. In order to preserve expected laziness behavior for the stream() and parallelStream() methods, spliterators should either have the characteristic of IMMUTABLE or CONCURRENT, or be late-binding. If none of these is practical, the overriding class should describe the spliterator's documented policy of binding and structural interference, and should override the stream() and parallelStream() methods to create streams using a Supplier of the spliterator, as in:
<code>Stream<E> s = StreamSupport.stream(() -> spliterator(), spliteratorCharacteristics) </code>
These requirements ensure that streams produced by the stream() and parallelStream() methods will reflect the contents of the collection as of initiation of the terminal stream operation.
| Return | |
|---|---|
Spliterator<K> |
a Spliterator over the elements in this set |
toArray
fun toArray(): Array<Any!>
Returns an array containing all of the elements in this collection. 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. The returned array's runtime component type is Object.
The 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.
| Return | |
|---|---|
Array<Any!> |
an array containing all the elements in this set |
toArray
fun <T : Any!> toArray(a: Array<T>): Array<T>
Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array. If the collection 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 collection.
If 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.
| Parameters | |
|---|---|
<T> |
the component type of the array to contain the collection |
a |
Array<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. |
| Return | |
|---|---|
Array<T> |
an array containing all the elements in this set |
| Exceptions | |
|---|---|
java.lang.ArrayStoreException |
if the runtime type of the specified array is not a supertype of the runtime type of every element in this set |
java.lang.NullPointerException |
if the specified array is null |
toString
fun toString(): String
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 by String.valueOf(Object).
| Return | |
|---|---|
String |
a string representation of this collection |
Properties
size
val size: Int
Returns the number of elements in this collection. If this collection contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
| Return | |
|---|---|
Int |
the number of elements in this set (its cardinality) |