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 implementingMappableinstance.
- 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
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:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceMappable.BaseList<T,B extends Mappable.BaseList<T, B>> A sub-interface ofMappablespecialized forListcollections.static interfaceMappable.BaseSet<T,B extends Mappable.BaseSet<T, B>> A sub-interface ofMappablespecialized forSetcollections. -
Method Summary
Modifier and TypeMethodDescriptiondefault BFilters the stored elements based on the given predicate, modifying the current instance.Retrieves all stored values merged into a single collection.default <V extends Collection<T>>
VgetStoredValues(Supplier<V> supplier) Retrieves all stored values merged into a single collection, using the provided supplier to create the collection.iterator()Returns an iterator over the map's entries.default Border(boolean ascendant) Orders the keys in ascending or descending order.order(Comparator<Integer> comparator) Orders the keys in the mapping based on the given comparator.Methods inherited from interface me.croabeast.common.builder.BaseBuilder
instanceMethods 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, values
-
Method Details
-
filter
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
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
Bwith the keys ordered accordingly.
-
order
Orders the keys in ascending or descending order.- Parameters:
ascendant- Iftrue, orders in ascending order; otherwise, orders in descending order.- Returns:
- A new instance of
Bwith the keys ordered as specified.
-
getStoredValues
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
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
Returns an iterator over the map's entries.
-