Interface Mappable<T,C extends Collection<T>,B extends Mappable<T,C,B>>

Type Parameters:
T - The type of elements stored in the collections.
C - The type of collection that holds the elements.
B - The type of the implementing Mappable instance.
All Superinterfaces:
BaseBuilder<B>, Copyable<B>, Iterable<Map.Entry<Integer,C>>, Map<Integer,C>
All Known Subinterfaces:
Mappable.BaseList<T,B>, Mappable.BaseSet<T,B>, SectionMappable<C,S>, SectionMappable.List, SectionMappable.Set, UnitMappable<U,C,UM>, UnitMappable.List<U>, UnitMappable.Set<U>
All Known Implementing Classes:
HashMappable

public interface Mappable<T,C extends Collection<T>,B extends Mappable<T,C,B>> extends Map<Integer,C>, Iterable<Map.Entry<Integer,C>>, BaseBuilder<B>, Copyable<B>
Represents a specialized mapping structure that associates integer keys with collections of elements.

Mappable extends Map and BaseBuilder to provide a fluent interface for performing operations such as filtering, ordering, and merging values across grouped collections.

Important: Concrete implementations of Mappable (as well as its sub-interfaces BaseSet and BaseList) must be provided to ensure full functionality. The default methods offered in these interfaces, such as getStoredValues(Supplier) and Copyable.copy(), rely on a proper implementation of the underlying storage. Without an implementation, methods like getStoredValues() (the no-argument version) will not function as expected.

For example, the BaseSet and BaseList sub-interfaces provide default implementations to convert the stored values into a Set or List respectively, but they require that you implement a concrete class that extends Mappable to fully support these operations.

Example usage:


 // Create a concrete implementation of Mappable (for instance, HashMappable)
 Mappable<String, List<String>, ?> mappable = new HashMappable<>();
 mappable.put(1, Arrays.asList("One", "Uno"));
 mappable.put(2, Arrays.asList("Two", "Dos"));

 // Use the default methods to merge all stored values into a List
 List<String> allValues = mappable.getStoredValues(ArrayList::new);
 System.out.println(allValues); // Outputs: [One, Uno, Two, Dos]
 

See Also:
  • Method Details

    • filter

      @NotNull default B filter(Predicate<T> predicate)
      Filters the stored elements based on the given predicate, modifying the current instance.
      Parameters:
      predicate - The condition used to filter elements.
      Returns:
      The modified instance of B, with non-matching elements removed.
    • order

      @NotNull B order(Comparator<Integer> comparator)
      Orders the keys in the mapping based on the given comparator.
      Parameters:
      comparator - The comparator used to order the keys.
      Returns:
      A new instance of B with the keys ordered accordingly.
    • order

      @NotNull default B order(boolean ascendant)
      Orders the keys in ascending or descending order.
      Parameters:
      ascendant - If true, orders in ascending order; otherwise, orders in descending order.
      Returns:
      A new instance of B with the keys ordered as specified.
    • getStoredValues

      @NotNull default <V extends Collection<T>> V getStoredValues(Supplier<V> supplier)
      Retrieves all stored values merged into a single collection, using the provided supplier to create the collection.
      Type Parameters:
      V - The type of the resulting collection.
      Parameters:
      supplier - The supplier used to create a new collection instance.
      Returns:
      A collection containing all stored values across all keys.
    • getStoredValues

      @NotNull C getStoredValues()
      Retrieves all stored values merged into a single collection.

      Note that this method must be implemented by a concrete class for full functionality.

      Returns:
      A collection containing all stored values.
    • iterator

      @NotNull default @NotNull Iterator<Map.Entry<Integer,C>> iterator()
      Returns an iterator over the map's entries.
      Specified by:
      iterator in interface Iterable<T>
      Returns:
      an iterator over Map.Entry objects containing the integer keys and corresponding collections.