Class Selectables
java.lang.Object
org.microbean.assign.Selectables
Utility methods for working with
Selectables.- Author:
- Laird Nelson
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <C,E> Selectable <C, E> caching(Selectable<C, E> selectable) Returns aSelectablethat caches its results.static <C,E> Selectable <C, E> caching(Selectable<C, E> selectable, BiFunction<? super C, Function<? super C, ? extends List<E>>, ? extends List<E>> f) Returns aSelectablethat caches its results.static final <C,E> Selectable <C, E> empty()Returns aSelectablewhoseSelectable.select(Object)method always returns an empty, immutableList.static <C,E> Selectable <C, E> filtering(Collection<? extends E> collection, BiPredicate<? super E, ? super C> p) Returns aSelectableusing the suppliedCollectionas its elements, and the suppliedBiPredicateas its selector.
-
Method Details
-
caching
Returns aSelectablethat caches its results.The cache is unbounded.
- Type Parameters:
C- the criteria typeE- the element type- Parameters:
selectable- aSelectable; must not benull- Returns:
- a non-
nullSelectable - Throws:
NullPointerException- ifselectableisnull- See Also:
-
caching
public static <C,E> Selectable<C,E> caching(Selectable<C, E> selectable, BiFunction<? super C, Function<? super C, ? extends List<E>>, ? extends List<E>> f) Returns aSelectablethat caches its results.- Type Parameters:
C- the criteria typeE- the element type- Parameters:
selectable- aSelectable; must not benullf- aBiFunctionthat returns a cached result, computing it on demand via its supplied mappingFunctionif necessary; must not benull; normally safe for concurrent use by multiple threads; often a reference to theConcurrentHashMap.computeIfAbsent(Object, Function)method- Returns:
- a non-
nullSelectable - Throws:
NullPointerException- ifselectableorfisnull- See Also:
-
empty
Returns aSelectablewhoseSelectable.select(Object)method always returns an empty, immutableList.This method is useful primarily for completeness and for testing pathological situations.
- Type Parameters:
C- the criteria typeE- the element type- Returns:
- a non-
nullSelectable
-
filtering
public static <C,E> Selectable<C,E> filtering(Collection<? extends E> collection, BiPredicate<? super E, ? super C> p) Returns aSelectableusing the suppliedCollectionas its elements, and the suppliedBiPredicateas its selector.There is no guarantee that this method will return new
Selectableinstances.The
Selectableinstances returned by this method may or may not cache their selections.The selector must (indirectly) designate a sublist from the supplied
Collectionas mediated by the supplied criteria. The selector must additionally be idempotent and must produce a determinate value when given the same arguments.No validation of these semantics of the selector is performed.
- Type Parameters:
C- the criteria typeE- the element type- Parameters:
collection- aCollectionof elements from which sublists may be selected; must not benullp- the selector; must not benull- Returns:
- a
Selectable; nevernull - Throws:
NullPointerException- if eithercollectionorpisnull
-