Class HashMappable<T,C extends Collection<T>>
- Type Parameters:
T- the type of elements stored in the collections.C- the type of collection that holds the elements.
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<Map.Entry<Integer,,C>> Map<Integer,,C> BaseBuilder<HashMappable<T,,C>> Copyable<HashMappable<T,,C>> Mappable<T,C, HashMappable<T, C>>
Mappable backed by a HashMap.
HashMappable associates integer keys with collections of elements of type T.
It extends HashMap<Integer, C> and implements the Mappable interface, providing
utility methods for ordering and copying the mapping. In addition, it stores a Supplier to
generate new instances of the collection type C when needed.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> Nested classes/interfaces inherited from interface me.croabeast.file.Mappable
Mappable.BaseList<T,B extends Mappable.BaseList<T, B>>, Mappable.BaseSet<T, B extends Mappable.BaseSet<T, B>> -
Constructor Summary
ConstructorsConstructorDescriptionHashMappable(Supplier<C> supplier) Constructs an emptyHashMappablewith the specified collection supplier.Constructs a newHashMappablewith the mappings copied from the provided map. -
Method Summary
Modifier and TypeMethodDescription@NotNull HashMappable<T, C> copy()Creates a shallow copy of thisHashMappable.Retrieves all stored values across all keys combined into a single collection.@NotNull HashMappable<T, C> instance()Returns this instance as aHashMappable.@NotNull HashMappable<T, C> order(Comparator<Integer> comparator) Orders the entries of thisHashMappableusing the provided comparator.Methods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, newHashMap, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, valuesMethods inherited from class java.util.AbstractMap
equals, hashCode, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, valuesMethods inherited from interface me.croabeast.file.Mappable
filter, getStoredValues, iterator, order
-
Constructor Details
-
HashMappable
Constructs an emptyHashMappablewith the specified collection supplier.- Parameters:
supplier- aSupplierused to create new collections of typeC; must not benull
-
HashMappable
Constructs a newHashMappablewith the mappings copied from the provided map.- Parameters:
supplier- aSupplierused to create new collections of typeC; must not benullmap- the map whose entries are to be placed in this mappable
-
-
Method Details
-
order
Orders the entries of thisHashMappableusing the provided comparator.This method creates a new ordered map (a
TreeMap) based on the given comparator, copies all entries into it, and then returns a newHashMappableinstance containing the ordered entries.- Specified by:
orderin interfaceMappable<T,C extends Collection<T>, HashMappable<T, C extends Collection<T>>> - Parameters:
comparator- the comparator used for ordering the keys; must not benull- Returns:
- a new
HashMappableinstance with entries ordered according to the comparator
-
copy
Creates a shallow copy of thisHashMappable.The returned copy contains the same keys and values as this instance. Note that the collections associated with each key are also copied using the supplier, but their elements are not deep-cloned.
-
getStoredValues
Retrieves all stored values across all keys combined into a single collection.This method collects all elements from each collection in the mapping and returns a new collection containing all these elements.
- Specified by:
getStoredValuesin interfaceMappable<T,C extends Collection<T>, HashMappable<T, C extends Collection<T>>> - Returns:
- a collection containing all values from the mapping
-
instance
Returns this instance as aHashMappable.- Specified by:
instancein interfaceBaseBuilder<T>- Returns:
- this
HashMappableinstance
-