Package extra166y
Class CustomConcurrentHashMap.KeySet<K>
java.lang.Object
java.util.AbstractCollection<K>
java.util.AbstractSet<K>
extra166y.CustomConcurrentHashMap.KeySet<K>
- All Implemented Interfaces:
Serializable,Iterable<K>,Collection<K>,Set<K>
- Enclosing class:
CustomConcurrentHashMap<K,V>
public static class CustomConcurrentHashMap.KeySet<K>
extends AbstractSet<K>
implements Set<K>, 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:
-
Constructor Summary
ConstructorsConstructorDescriptionKeySet(CustomConcurrentHashMap.Strength strength, CustomConcurrentHashMap.Equivalence<? super K> equivalence, int expectedSize) Creates a set with the given parameters -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds 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.voidclear()Removes all of the elements from this set.booleanReturns true if this set contains an element equivalent to the given element with respect to this set's Equivalence.inthashCode()Returns the sum of the hash codes of each element, as computed by this set's Equivalence.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.booleanisEmpty()Returns true if this set contains no elements.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.booleanRemoves an element equivalent to the given element with respect to this set's Equivalence, if one is present.intsize()Returns the number of elements in this set (its cardinality).Methods inherited from class java.util.AbstractSet
equals, removeAllMethods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.Set
addAll, containsAll, equals, removeAll, retainAll, spliterator, toArray, toArray
-
Constructor Details
-
KeySet
public KeySet(CustomConcurrentHashMap.Strength strength, CustomConcurrentHashMap.Equivalence<? super K> equivalence, int expectedSize) Creates a set with the given parameters- Parameters:
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.
-
-
Method Details
-
intern
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
Returns true if this set contains an element equivalent to the given element with respect to this set's Equivalence.- Specified by:
containsin interfaceCollection<K>- Specified by:
containsin interfaceSet<K>- Overrides:
containsin classAbstractCollection<K>- Parameters:
o- element whose presence in this set is to be tested- Returns:
- true if this set contains the specified element
-
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. -
add
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:
addin interfaceCollection<K>- Specified by:
addin interfaceSet<K>- Overrides:
addin classAbstractCollection<K>- Parameters:
e- element to be added to this set- Returns:
- true if this set did not already contain the specified element
-
remove
Removes an element equivalent to the given element with respect to this set's Equivalence, if one is present.- Specified by:
removein interfaceCollection<K>- Specified by:
removein interfaceSet<K>- Overrides:
removein classAbstractCollection<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:
isEmptyin interfaceCollection<K>- Specified by:
isEmptyin interfaceSet<K>- Overrides:
isEmptyin classAbstractCollection<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:
sizein interfaceCollection<K>- Specified by:
sizein interfaceSet<K>- Specified by:
sizein classAbstractCollection<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:
clearin interfaceCollection<K>- Specified by:
clearin interfaceSet<K>- Overrides:
clearin classAbstractCollection<K>
-
hashCode
public int hashCode()Returns the sum of the hash codes of each element, as computed by this set's Equivalence.- Specified by:
hashCodein interfaceCollection<K>- Specified by:
hashCodein interfaceSet<K>- Overrides:
hashCodein classAbstractSet<K>- Returns:
- the hash code
-