public static class CustomConcurrentHashMap.KeySet<K> extends AbstractSet<K> implements Set<K>, Serializable
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.Constructor and Description |
---|
KeySet(CustomConcurrentHashMap.Strength strength,
CustomConcurrentHashMap.Equivalence<? super K> equivalence,
int expectedSize)
Creates a set with the given parameters
|
Modifier and Type | Method and Description |
---|---|
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(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.
|
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(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).
|
equals, removeAll
addAll, containsAll, retainAll, toArray, toArray, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
addAll, containsAll, equals, removeAll, retainAll, spliterator, toArray, toArray
parallelStream, removeIf, stream
public KeySet(CustomConcurrentHashMap.Strength strength, CustomConcurrentHashMap.Equivalence<? super K> equivalence, int expectedSize)
strength
- the strength of elementsequivalence
- the Equivalence to useexpectedSize
- an estimate of the number of elements
that will be held in the set. If no estimate is known, zero
is an acceptable value.public K intern(K e)
e
- the elementpublic boolean contains(Object o)
contains
in interface Collection<K>
contains
in interface Set<K>
contains
in class AbstractCollection<K>
o
- element whose presence in this set is to be testedpublic Iterator<K> iterator()
public boolean add(K e)
add
in interface Collection<K>
add
in interface Set<K>
add
in class AbstractCollection<K>
e
- element to be added to this setpublic boolean remove(Object o)
remove
in interface Collection<K>
remove
in interface Set<K>
remove
in class AbstractCollection<K>
o
- object to be removed from this set, if presentpublic boolean isEmpty()
isEmpty
in interface Collection<K>
isEmpty
in interface Set<K>
isEmpty
in class AbstractCollection<K>
public int size()
size
in interface Collection<K>
size
in interface Set<K>
size
in class AbstractCollection<K>
public void clear()
clear
in interface Collection<K>
clear
in interface Set<K>
clear
in class AbstractCollection<K>
public int hashCode()
hashCode
in interface Collection<K>
hashCode
in interface Set<K>
hashCode
in class AbstractSet<K>