Class ConcurrentHashMap.KeySetView<K,​V>

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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)
      Tests whether this Collection contains the specified object.
      boolean containsAll​(Collection<?> c)
      Tests whether this Collection contains all objects contained in the specified Collection.
      boolean equals​(Object o)
      Compares this instance with the specified object and indicates if they are equal.
      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 if this Collection contains no elements.
      Iterator<K> iterator()
      Returns a "weakly consistent" iterator that will never throw ConcurrentModificationException, and guarantees to traverse elements as they existed upon construction of the iterator, and may (but is not guaranteed to) reflect any modifications subsequent to construction.
      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 occurrences in this Collection of each object in the specified Collection (optional).
      boolean retainAll​(Collection<?> c)
      Removes all objects from this Collection that are not also found in the Collection passed (optional).
      int size()
      Returns a count of how many objects this Collection contains.
      Object[] toArray()
      Returns a new array containing all elements contained in this Collection.
      <T> T[] toArray​(T[] a)
      Returns an array containing all elements contained in this Collection.
      String toString()
      Returns a string representation of this collection.
    • Method Detail

      • getMappedValue

        public V getMappedValue()
        Returns the default mapped value for additions, or null if additions are not supported.
        Returns:
        the default mapped value for additions, or null if not supported
      • contains

        public boolean contains​(Object o)
        Tests whether this Collection contains the specified object. Returns true if and only if at least one element elem in this Collection meets following requirement: (object==null ? elem==null : object.equals(elem)).
        Specified by:
        contains in interface Collection<K>
        Specified by:
        contains in interface Set<K>
        Parameters:
        o - the object to search for.
        Returns:
        true if object is an element of this Collection, false otherwise.
        Throws:
        NullPointerException - if the specified key is null
      • remove

        public boolean remove​(Object o)
        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 interface Collection<K>
        Specified by:
        remove in interface Set<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

        public Iterator<K> iterator()
        Returns a "weakly consistent" iterator that will never throw ConcurrentModificationException, and guarantees to traverse elements as they existed upon construction of the iterator, and may (but is not guaranteed to) reflect any modifications subsequent to construction.
        Specified by:
        iterator in interface Collection<K>
        Specified by:
        iterator in interface Iterable<K>
        Specified by:
        iterator in interface Set<K>
        Returns:
        an iterator over the keys of the backing map
        See Also:
        Iterator
      • add

        public 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.
        Specified by:
        add in interface Collection<K>
        Specified by:
        add in interface Set<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 null
        UnsupportedOperationException - if no default mapped value for additions was provided
      • addAll

        public 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.
        Specified by:
        addAll in interface Collection<K>
        Specified by:
        addAll in interface Set<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 are null
        UnsupportedOperationException - if no default mapped value for additions was provided
      • hashCode

        public int hashCode()
        Description copied from class: Object
        Returns an integer hash code for this object. By contract, any two objects for which Object.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.

        Specified by:
        hashCode in interface Collection<K>
        Specified by:
        hashCode in interface Set<K>
        Overrides:
        hashCode in class Object
        Returns:
        this object's hash code.
        See Also:
        Object.equals(java.lang.Object)
      • equals

        public boolean equals​(Object o)
        Description copied from class: Object
        Compares this instance with the specified object and indicates if they are equal. In order to be equal, o 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.

        Specified by:
        equals in interface Collection<K>
        Specified by:
        equals in interface Set<K>
        Overrides:
        equals in class Object
        Parameters:
        o - the object to compare this instance with.
        Returns:
        true if the specified object is equal to this Object; false otherwise.
        See Also:
        Object.hashCode()
      • getMap

        public ConcurrentHashMap<K,​V> getMap()
        Returns the map backing this view.
        Returns:
        the map backing this view
      • size

        public final int size()
        Description copied from interface: Collection
        Returns a count of how many objects this Collection contains.
        Specified by:
        size in interface Collection<K>
        Returns:
        how many objects this Collection contains, or Integer.MAX_VALUE if there are more than Integer.MAX_VALUE elements in this Collection.
      • isEmpty

        public final boolean isEmpty()
        Description copied from interface: Collection
        Returns if this Collection contains no elements.
        Specified by:
        isEmpty in interface Collection<K>
        Returns:
        true if this Collection has no elements, false otherwise.
        See Also:
        Collection.size()
      • toArray

        public final Object[] toArray()
        Description copied from interface: Collection
        Returns a new array containing all elements contained in this Collection. If the implementation has ordered elements it will return the element array in the same order as an iterator would return them. The array returned does not reflect any changes of the Collection. A new array is created even if the underlying data structure is already an array.
        Specified by:
        toArray in interface Collection<K>
        Returns:
        an array of the elements from this Collection.
      • toArray

        public final <T> T[] toArray​(T[] a)
        Description copied from interface: Collection
        Returns an array containing all elements contained in this Collection. If the specified array is large enough to hold the elements, the specified array is used, otherwise an array of the same type is created. If the specified array is used and is larger than this Collection, the array element following the Collection elements is set to null. If the implementation has ordered elements it will return the element array in the same order as an iterator would return them. toArray(new Object[0]) behaves exactly the same way as toArray() does.
        Specified by:
        toArray in interface Collection<K>
        Parameters:
        a - the array.
        Returns:
        an array of the elements from this Collection.
      • toString

        public final String 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 by String.valueOf(Object).
        Overrides:
        toString in class Object
        Returns:
        a string representation of this collection
      • containsAll

        public final boolean containsAll​(Collection<?> c)
        Description copied from interface: Collection
        Tests whether this Collection contains all objects contained in the specified Collection. If an element elem is contained several times in the specified Collection, the method returns true even if elem is contained only once in this Collection.
        Specified by:
        containsAll in interface Collection<K>
        Parameters:
        c - the collection of objects.
        Returns:
        true if all objects in the specified Collection are elements of this Collection, false otherwise.
      • removeAll

        public final boolean removeAll​(Collection<?> c)
        Description copied from interface: Collection
        Removes all occurrences in this Collection of each object in the specified Collection (optional). After this method returns none of the elements in the passed Collection can be found in this Collection anymore.
        Specified by:
        removeAll in interface Collection<K>
        Parameters:
        c - the collection of objects to remove.
        Returns:
        true if this Collection is modified, false otherwise.
      • retainAll

        public final boolean retainAll​(Collection<?> c)
        Description copied from interface: Collection
        Removes all objects from this Collection that are not also found in the Collection passed (optional). After this method returns this Collection will only contain elements that also can be found in the Collection passed to this method.
        Specified by:
        retainAll in interface Collection<K>
        Parameters:
        c - the collection of objects to retain.
        Returns:
        true if this Collection is modified, false otherwise.