groovyx.gpars.extra166y
Class CustomConcurrentHashMap.KeySet<K>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<K>
          extended by groovyx.gpars.extra166y.CustomConcurrentHashMap.KeySet<K>
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<K>, java.util.Collection<K>, java.util.Set<K>
Enclosing class:
CustomConcurrentHashMap<K,V>

public static class CustomConcurrentHashMap.KeySet<K>
extends java.util.AbstractSet<K>
implements java.util.Set<K>, java.io.Serializable

A hash-based set with properties identical to those of Collections.newSetFromMap applied to a CustomConcurrentHashMap, but possibly more space-efficient. The set does not permit null elements. The set is serializable; however, serializing a set that uses soft or weak references can give unpredictable results.

See Also:
Serialized Form

Field Summary
(package private)  CustomConcurrentHashMap<K,K> cchm
           
 
Constructor Summary
CustomConcurrentHashMap.KeySet(CustomConcurrentHashMap.Strength strength, CustomConcurrentHashMap.Equivalence<? super K> equivalence, int expectedSize)
          Creates a set with the given parameters
 
Method Summary
 boolean add(K e)
          Adds the specified element to this set if there is not already an element equivalent to the given element with respect to this set's Equivalence.
 void clear()
          Removes all of the elements from this set.
 boolean contains(java.lang.Object o)
          Returns true if this set contains an element equivalent to the given element with respect to this set's Equivalence.
 int hashCode()
          Returns the sum of the hash codes of each element, as computed by this set's Equivalence.
 K intern(K e)
          Returns an element equivalent to the given element with respect to this set's Equivalence, if such an element exists, else adds and returns the given element.
 boolean isEmpty()
          Returns true if this set contains no elements.
 java.util.Iterator<K> iterator()
          Returns a weakly consistent iterator over the elements in this set, that may reflect some, all or none of the changes made to the set after the iterator was created.
 boolean remove(java.lang.Object o)
          Removes an element equivalent to the given element with respect to this set's Equivalence, if one is present.
 int size()
          Returns the number of elements in this set (its cardinality).
 
Methods inherited from class java.util.AbstractSet
equals, removeAll
 
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
addAll, containsAll, equals, removeAll, retainAll, toArray, toArray
 

Field Detail

cchm

final CustomConcurrentHashMap<K,K> cchm
Constructor Detail

CustomConcurrentHashMap.KeySet

public CustomConcurrentHashMap.KeySet(CustomConcurrentHashMap.Strength strength,
                                      CustomConcurrentHashMap.Equivalence<? super K> equivalence,
                                      int expectedSize)
Creates a set with the given parameters

Parameters:
strength - the strength of elements
equivalence - the Equivalence to use
expectedSize - an estimate of the number of elements that will be held in the set. If no estimate is known, zero is an acceptable value.
Method Detail

intern

public K intern(K e)
Returns an element equivalent to the given element with respect to this set's Equivalence, if such an element exists, else adds and returns the given element.

Parameters:
e - the element
Returns:
e, or an element equivalent to e.

contains

public boolean contains(java.lang.Object o)
Returns true if this set contains an element equivalent to the given element with respect to this set's Equivalence.

Specified by:
contains in interface java.util.Collection<K>
Specified by:
contains in interface java.util.Set<K>
Overrides:
contains in class java.util.AbstractCollection<K>
Parameters:
o - element whose presence in this set is to be tested
Returns:
true if this set contains the specified element

iterator

public java.util.Iterator<K> iterator()
Returns a weakly consistent iterator over the elements in this set, that may reflect some, all or none of the changes made to the set after the iterator was created.

Specified by:
iterator in interface java.lang.Iterable<K>
Specified by:
iterator in interface java.util.Collection<K>
Specified by:
iterator in interface java.util.Set<K>
Specified by:
iterator in class java.util.AbstractCollection<K>
Returns:
an Iterator over the elements in this set

add

public boolean add(K e)
Adds the specified element to this set if there is not already an element equivalent to the given element with respect to this set's Equivalence.

Specified by:
add in interface java.util.Collection<K>
Specified by:
add in interface java.util.Set<K>
Overrides:
add in class java.util.AbstractCollection<K>
Parameters:
e - element to be added to this set
Returns:
true if this set did not already contain the specified element

remove

public boolean remove(java.lang.Object o)
Removes an element equivalent to the given element with respect to this set's Equivalence, if one is present.

Specified by:
remove in interface java.util.Collection<K>
Specified by:
remove in interface java.util.Set<K>
Overrides:
remove in class java.util.AbstractCollection<K>
Parameters:
o - object to be removed from this set, if present
Returns:
true if the set contained the specified element

isEmpty

public boolean isEmpty()
Returns true if this set contains no elements.

Specified by:
isEmpty in interface java.util.Collection<K>
Specified by:
isEmpty in interface java.util.Set<K>
Overrides:
isEmpty in class java.util.AbstractCollection<K>
Returns:
true if this set contains no elements

size

public int size()
Returns the number of elements in this set (its cardinality).

Specified by:
size in interface java.util.Collection<K>
Specified by:
size in interface java.util.Set<K>
Specified by:
size in class java.util.AbstractCollection<K>
Returns:
the number of elements in this set (its cardinality)

clear

public void clear()
Removes all of the elements from this set.

Specified by:
clear in interface java.util.Collection<K>
Specified by:
clear in interface java.util.Set<K>
Overrides:
clear in class java.util.AbstractCollection<K>

hashCode

public int hashCode()
Returns the sum of the hash codes of each element, as computed by this set's Equivalence.

Specified by:
hashCode in interface java.util.Collection<K>
Specified by:
hashCode in interface java.util.Set<K>
Overrides:
hashCode in class java.util.AbstractSet<K>
Returns:
the hash code

Copyright © 2008–2012 Václav Pech. All Rights Reserved.