Class HashSetMap<K,V>
java.lang.Object
org.javimmutable.collections.setmap.HashSetMap<K,V>
- All Implemented Interfaces:
Serializable,Iterable<IMapEntry<K,,ISet<V>>> ICollection<IMapEntry<K,,ISet<V>>> InvariantCheckable,ISetMap<K,,V> IStreamable<IMapEntry<K,,ISet<V>>> Mapped<K,,ISet<V>> SplitableIterable<IMapEntry<K,ISet<V>>>
ISetMap using a hash map for fast lookup.- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionSets the set associated with a specific key.voidChecks invariants of implementing class.protected voidbooleanDetermines if the setmap contains the specified key.booleanDetermines if the Set at key contains the specified value.booleancontainsAll(K key, Iterable<? extends V> values) Determines if the Set at key contains all values in the specified collection.booleancontainsAll(K key, Iterator<? extends V> values) Determines if the Set at key contains all values in the specified collection.booleancontainsAny(K key, Iterable<? extends V> values) Determines if the Set at key contains any values in the specified collection.booleancontainsAny(K key, Iterator<? extends V> values) Determines if the Set at key contains any values in the specified collection.Implemented by derived classes to create a new instance of the appropriate class.Deletes the entry for the specified key (if any).Deletes the specified value from the specified key's set.Deletes the elements in other at the specified key.Deletes the elements in other at the specified key.IStreamable<IMapEntry<K, ISet<V>>> entries()Creates an IStreamable to access all of the Map's entries.booleanReturn a Holder containing the value associated wth the key or an empty Holder if no value is associated with the key.Return the value associated with key or null if no value is associated.Return the set associated with key, or an empty set if no list is associated.intgetValueOr(K key, ISet<V> defaultValue) Return the value associated with key or defaultValue if no value is associated.inthashCode()Add value to the Set for the specified key.Add value to the Set for the specified key.Add all values to the container in some manner appropriate to the implementation.Adds all of the elements of the specified Iterable to the Set for the specified key.Adds all of the elements of the specified collection to the Set for the specified key.intersection(K key, Iterable<? extends V> other) Removes all values from the Set at key that are not contained in the other collection.intersection(K key, Iterator<? extends V> other) Removes all values from the Set at key that are not contained in the other collection.intersection(K key, Set<? extends V> other) Removes all values from the Set at key that are not contained in the other collection.intersection(K key, ISet<? extends V> other) Removes all values from the Set at key that are not contained in the other collection.booleanisEmpty()iterator()Overridden here to require implementations to return a SplitableIterator rather than a basic Iterator.keys()Creates an IStreamable to access all of the Map's keys.static <K,V> HashSetMap <K, V> of()intsize()Return the number of keys in the map.toString()Adds all values from other to the Set at keyAdds all values from other to the Set at keyCreates an IStreamable to access all of the specified key's set.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.javimmutable.collections.ICollection
isNonEmptyMethods inherited from interface org.javimmutable.collections.ISetMap
forEach, forEachThrows, insertAll, setMapCollector, transform, transformIfPresentMethods inherited from interface org.javimmutable.collections.IStreamable
parallelStream, spliterator, streamMethods inherited from interface org.javimmutable.collections.SplitableIterable
forEachThrows, indexedForEach, indexedForEachThrows, reduce, reduceThrows
-
Field Details
-
emptySet
-
contents
-
-
Method Details
-
of
-
checkInvariants
public void checkInvariants()Description copied from interface:InvariantCheckableChecks invariants of implementing class.- Specified by:
checkInvariantsin interfaceInvariantCheckable
-
create
Implemented by derived classes to create a new instance of the appropriate class. -
getSet
Description copied from interface:ISetMapReturn the set associated with key, or an empty set if no list is associated. -
assign
Description copied from interface:ISetMapSets the set associated with a specific key. Key and value must be non-null. If the key already has a set in the map the old set is discarded and the new set is stored in its place. Returns a newISetMapreflecting any changes. The original map is always left unchanged. -
insert
Description copied from interface:ISetMapAdd value to the Set for the specified key. Note that if the value has already been added, it will not be added again. -
insertAll
Description copied from interface:ISetMapAdds all of the elements of the specified Iterable to the Set for the specified key. -
insertAll
Description copied from interface:ISetMapAdds all of the elements of the specified collection to the Set for the specified key. -
insertAll
Description copied from interface:ICollectionAdd all values to the container in some manner appropriate to the implementation.- Specified by:
insertAllin interfaceICollection<K>- Specified by:
insertAllin interfaceISetMap<K,V>
-
contains
Description copied from interface:ISetMapDetermines if the setmap contains the specified key. -
contains
Description copied from interface:ISetMapDetermines if the Set at key contains the specified value. -
containsAll
Description copied from interface:ISetMapDetermines if the Set at key contains all values in the specified collection.- Specified by:
containsAllin interfaceISetMap<K,V> - Returns:
- true if the Set contains the values
-
containsAll
Description copied from interface:ISetMapDetermines if the Set at key contains all values in the specified collection.- Specified by:
containsAllin interfaceISetMap<K,V> - Returns:
- true if the Set contains the values
-
containsAny
Description copied from interface:ISetMapDetermines if the Set at key contains any values in the specified collection.- Specified by:
containsAnyin interfaceISetMap<K,V> - Returns:
- true if the Set contains a value
-
containsAny
Description copied from interface:ISetMapDetermines if the Set at key contains any values in the specified collection.- Specified by:
containsAnyin interfaceISetMap<K,V> - Returns:
- true if the Set contains a value
-
delete
Description copied from interface:ISetMapDeletes the entry for the specified key (if any). Returns a new map if the value was deleted or the current map if the key was not contained in the map. -
delete
Description copied from interface:ISetMapDeletes the specified value from the specified key's set. Returns a new map if the value was deleted or the current map if the key was not contained in the map. -
deleteAll
Description copied from interface:ISetMapDeletes the elements in other at the specified key. Returns a new map if the values were deleted or the current map if the key was not contained in the map. -
deleteAll
Description copied from interface:ISetMapDeletes the elements in other at the specified key. Returns a new map if the values were deleted or the current map if the key was not contained in the map. -
union
Description copied from interface:ISetMapAdds all values from other to the Set at key -
union
Description copied from interface:ISetMapAdds all values from other to the Set at key -
intersection
Description copied from interface:ISetMapRemoves all values from the Set at key that are not contained in the other collection. If the given key is not present in the map, an empty set is added to the map.- Specified by:
intersectionin interfaceISetMap<K,V>
-
intersection
Description copied from interface:ISetMapRemoves all values from the Set at key that are not contained in the other collection. If the given key is not present in the map, an empty set is added to the map.- Specified by:
intersectionin interfaceISetMap<K,V>
-
intersection
Description copied from interface:ISetMapRemoves all values from the Set at key that are not contained in the other collection. If the given key is not present in the map, an empty set is added to the map.- Specified by:
intersectionin interfaceISetMap<K,V>
-
intersection
Description copied from interface:ISetMapRemoves all values from the Set at key that are not contained in the other collection. If the given key is not present in the map, an empty set is added to the map.- Specified by:
intersectionin interfaceISetMap<K,V>
-
size
public int size()Description copied from interface:ISetMapReturn the number of keys in the map.- Specified by:
sizein interfaceICollection<K>- Specified by:
sizein interfaceISetMap<K,V> - Returns:
- number of values in the collection
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceICollection<K>- Returns:
- true only if collection contains no values
-
insert
Description copied from interface:ISetMapAdd value to the Set for the specified key. Note that if the value has already been added, it will not be added again.- Specified by:
insertin interfaceICollection<K>- Specified by:
insertin interfaceISetMap<K,V>
-
iterator
Description copied from interface:IStreamableOverridden here to require implementations to return a SplitableIterator rather than a basic Iterator. This is necessary to allow composition of new objects from methods like keys() and values().- Specified by:
iteratorin interfaceIStreamable<K>- Specified by:
iteratorin interfaceIterable<K>- Specified by:
iteratorin interfaceSplitableIterable<K>
-
getSpliteratorCharacteristics
public int getSpliteratorCharacteristics()- Specified by:
getSpliteratorCharacteristicsin interfaceIStreamable<K>- Returns:
- characteristics value used when creating Spliterators
-
keys
Description copied from interface:ISetMapCreates an IStreamable to access all of the Map's keys. -
values
Description copied from interface:ISetMapCreates an IStreamable to access all of the specified key's set. If no set exists for key an empty IStreamable is returned. -
get
Description copied from interface:MappedReturn the value associated with key or null if no value is associated. Note that if null is an acceptable value to the container then this method will be ambiguous and find() should be used instead. -
getValueOr
Description copied from interface:MappedReturn the value associated with key or defaultValue if no value is associated. Note that if defaultValue is an acceptable value to the container then this method will be ambiguous and find() should be used instead.- Specified by:
getValueOrin interfaceMapped<K,V> - Parameters:
key- identifies the value to retrievedefaultValue- value to return if no entry exists for key- Returns:
- value associated with key or defaultValue if no value is associated
-
find
Description copied from interface:MappedReturn a Holder containing the value associated wth the key or an empty Holder if no value is associated with the key. -
deleteAll
- Specified by:
deleteAllin interfaceICollection<K>- Specified by:
deleteAllin interfaceISetMap<K,V> - Returns:
- an equivalent collection with no values
-
entries
Description copied from interface:ISetMapCreates an IStreamable to access all of the Map's entries. -
hashCode
public int hashCode() -
equals
-
toString
-
checkSetMapInvariants
protected void checkSetMapInvariants()
-