Class QuantumIdentityHashSet<K>
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<K>,Collection<K>,Set<K>
QuantumIdentityHashMap allocates more memory for the value.- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new, empty identity hash map with a default expected maximum size (21).QuantumIdentityHashSet(int expectedMaxSize) Constructs a new, empty map with the specified expected maximum size. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAssociates the specified value with the specified key in this identity hash map.booleanaddAll(@NonNull Collection<? extends K> c) voidclear()Removes all of the mappings from this map.clone()Returns a shallow copy of this identity hash map: the keys and values themselves are not cloned.booleanReturns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.booleancontainsAll(@NonNull Collection<?> c) voidbooleanisEmpty()Returnstrueif this identity hash map contains no key-value mappings.iterator()Returns an identity-based set view of the keys contained in this map.voidCopies all of the mappings from the specified map to this map.booleanRemoves the mapping for this key from this map if present.booleanremoveAll(@NonNull Collection<?> c) booleanretainAll(@NonNull Collection<?> c) intsize()Returns the number of key-value mappings in this identity hash map.Object[]toArray()<T> T[]toArray(T[] a) toString()Returns a string representation of this collection.Methods inherited from class java.util.AbstractSet
equals, hashCodeMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Constructor Details
-
QuantumIdentityHashSet
public QuantumIdentityHashSet()Constructs a new, empty identity hash map with a default expected maximum size (21). -
QuantumIdentityHashSet
public QuantumIdentityHashSet(int expectedMaxSize) Constructs a new, empty map with the specified expected maximum size. Putting more than the expected number of key-value mappings into the map may cause the internal data structure to grow, which may be somewhat time-consuming.- Parameters:
expectedMaxSize- the expected maximum size of the map- Throws:
IllegalArgumentException- ifexpectedMaxSizeis negative
-
-
Method Details
-
size
public int size()Returns the number of key-value mappings in this identity hash map.- Specified by:
sizein interfaceCollection<K>- Specified by:
sizein interfaceSet<K>- Specified by:
sizein classAbstractCollection<K>- Returns:
- the number of key-value mappings in this map
-
isEmpty
public boolean isEmpty()Returnstrueif this identity hash map contains no key-value mappings.- Specified by:
isEmptyin interfaceCollection<K>- Specified by:
isEmptyin interfaceSet<K>- Overrides:
isEmptyin classAbstractCollection<K>- Returns:
trueif this identity hash map contains no key-value mappings
-
contains
Returns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.More formally, if this map contains a mapping from a key
kto a valuevsuch that(key == k), then this method returnsv; otherwise it returnsnull. (There can be at most one such mapping.)A return value of
nulldoes not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key tonull. Thecontains(Object)} operation may be used to distinguish these two cases.- Specified by:
containsin interfaceCollection<K>- Specified by:
containsin interfaceSet<K>- Overrides:
containsin classAbstractCollection<K>- See Also:
-
iterator
Returns an identity-based set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress, the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via theIterator.remove,Set.remove,removeAll,retainAll, andclearmethods. It does not support theaddoraddAllmethods.While the object returned by this method implements the
Setinterface, it does not obeySet'sgeneral contract. Like its backing map, the set returned by this method defines element equality as reference-equality rather than object-equality. This affects the behavior of itscontains,remove,containsAll,equals, andhashCodemethods.The
equalsmethod of the returned set returnstrueonly if the specified object is a set containing exactly the same object references as the returned set. The symmetry and transitivity requirements of theObject.equalscontract may be violated if the set returned by this method is compared to a normal set. However, theObject.equalscontract is guaranteed to hold among sets returned by this method.The
hashCodemethod of the returned set returns the sum of the identity hashcodes of the elements in the set, rather than the sum of their hashcodes. This is mandated by the change in the semantics of theequalsmethod, in order to enforce the general contract of theObject.hashCodemethod among sets returned by this method. -
add
Associates the specified value with the specified key in this identity hash map. If the map previously contained a mapping for the key, the old value is replaced.- Specified by:
addin interfaceCollection<K>- Specified by:
addin interfaceSet<K>- Overrides:
addin classAbstractCollection<K>- Parameters:
key- the key with which the specified value is to be associated- Returns:
- the previous value associated with
key, ornullif there was no mapping forkey. (Anullreturn can also indicate that the map previously associatednullwithkey.) - See Also:
-
putAll
Copies all of the mappings from the specified map to this map. These mappings will replace any mappings that this map had for any of the keys currently in the specified map.- Parameters:
m- mappings to be stored in this map- Throws:
NullPointerException- if the specified map is null
-
remove
Removes the mapping for this key from this map if present.- Specified by:
removein interfaceCollection<K>- Specified by:
removein interfaceSet<K>- Overrides:
removein classAbstractCollection<K>- Parameters:
key- key whose mapping is to be removed from the map- Returns:
- true, otherwise false if there was no mapping for
key.
-
containsAll
- Specified by:
containsAllin interfaceCollection<K>- Specified by:
containsAllin interfaceSet<K>- Overrides:
containsAllin classAbstractCollection<K>
-
addAll
- Specified by:
addAllin interfaceCollection<K>- Specified by:
addAllin interfaceSet<K>- Overrides:
addAllin classAbstractCollection<K>
-
retainAll
- Specified by:
retainAllin interfaceCollection<K>- Specified by:
retainAllin interfaceSet<K>- Overrides:
retainAllin classAbstractCollection<K>
-
toString
Returns a string representation of this collection. The string representation consists of a list of the collection's elements in the order they are returned by its iterator, enclosed in square brackets ("QuantumIdentityHashSet[]"). Adjacent elements are separated by the characters", "(comma and space). Elements are converted to strings as byString.valueOf(Object).- Overrides:
toStringin classAbstractCollection<K>- Returns:
- a string representation of this collection
-
clear
public void clear()Removes all of the mappings from this map. The map will be empty after this call returns.- Specified by:
clearin interfaceCollection<K>- Specified by:
clearin interfaceSet<K>- Overrides:
clearin classAbstractCollection<K>
-
clone
Returns a shallow copy of this identity hash map: the keys and values themselves are not cloned. -
removeAll
- Specified by:
removeAllin interfaceCollection<K>- Specified by:
removeAllin interfaceSet<K>- Overrides:
removeAllin classAbstractSet<K>
-
toArray
- Specified by:
toArrayin interfaceCollection<K>- Specified by:
toArrayin interfaceSet<K>- Overrides:
toArrayin classAbstractCollection<K>
-
toArray
public <T> T[] toArray(T[] a) - Specified by:
toArrayin interfaceCollection<K>- Specified by:
toArrayin interfaceSet<K>- Overrides:
toArrayin classAbstractCollection<K>
-
spliterator
- Specified by:
spliteratorin interfaceCollection<K>- Specified by:
spliteratorin interfaceIterable<K>- Specified by:
spliteratorin interfaceSet<K>
-
forEach
-