Class HashMappable<T,C extends Collection<T>>

java.lang.Object
java.util.AbstractMap<Integer,C>
java.util.HashMap<Integer,C>
me.croabeast.file.HashMappable<T,C>
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>>

public class HashMappable<T,C extends Collection<T>> extends HashMap<Integer,C> implements Mappable<T,C,HashMappable<T,C>>
A concrete implementation of 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:
  • Constructor Details

    • HashMappable

      public HashMappable(Supplier<C> supplier)
      Constructs an empty HashMappable with the specified collection supplier.
      Parameters:
      supplier - a Supplier used to create new collections of type C; must not be null
    • HashMappable

      public HashMappable(Supplier<C> supplier, Map<Integer,? extends C> map)
      Constructs a new HashMappable with the mappings copied from the provided map.
      Parameters:
      supplier - a Supplier used to create new collections of type C; must not be null
      map - the map whose entries are to be placed in this mappable
  • Method Details

    • order

      @NotNull public @NotNull HashMappable<T,C> order(Comparator<Integer> comparator)
      Orders the entries of this HashMappable using 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 new HashMappable instance containing the ordered entries.

      Specified by:
      order in interface Mappable<T,C extends Collection<T>,HashMappable<T,C extends Collection<T>>>
      Parameters:
      comparator - the comparator used for ordering the keys; must not be null
      Returns:
      a new HashMappable instance with entries ordered according to the comparator
    • copy

      @NotNull public @NotNull HashMappable<T,C> copy()
      Creates a shallow copy of this HashMappable.

      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.

      Specified by:
      copy in interface Copyable<T>
      Returns:
      a new HashMappable instance with the same data as this instance.
    • getStoredValues

      @NotNull public C 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:
      getStoredValues in interface Mappable<T,C extends Collection<T>,HashMappable<T,C extends Collection<T>>>
      Returns:
      a collection containing all values from the mapping
    • instance

      @NotNull public @NotNull HashMappable<T,C> instance()
      Returns this instance as a HashMappable.
      Specified by:
      instance in interface BaseBuilder<T>
      Returns:
      this HashMappable instance