Class Selectables
Selectables.- Author:
- Laird Nelson
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <C,E> Selectable <C, E> caching(Selectable<? super C, E> selectable) Returns aSelectablethat caches its results.static <C,E> Selectable <C, E> caching(Selectable<? super C, E> selectable, BiFunction<? super C, Function<? super C, ? extends List<E>>, ? extends List<E>> f) Returns aSelectablethat caches its results.static <C extends AnnotatedConstruct, E>
Selectable<C, E> convert(Selectable<? super Annotated<C>, E> s) Deprecated, for removal: This API element is subject to removal in a future version.static <C extends AnnotatedConstruct, E>
Selectable<C, E> convert(Selectable<? super Annotated<C>, E> s, Predicate<? super ExecutableElement> annotationElementInclusionPredicate) Deprecated, for removal: This API element is subject to removal in a future version.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<? super 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:
-
convert
@Deprecated(forRemoval=true) public static <C extends AnnotatedConstruct, E> Selectable<C,E> convert(Selectable<? super Annotated<C>, E> s) Deprecated, for removal: This API element is subject to removal in a future version.An experimental method that converts aSelectableacceptingAnnotated<AnnotatedConstruct>instances into aSelectableacceptingAnnotatedConstructinstances.- Type Parameters:
C- the criteria typeE- the element type- Parameters:
s- a non-nullSelectableacceptingAnnotated<AnnotatedConstruct>instances- Returns:
- a non-
null, determinateSelectableacceptingAnnotatedConstructinstances - Throws:
NullPointerException- ifsisnull- See Also:
-
convert
@Deprecated(forRemoval=true) public static <C extends AnnotatedConstruct, E> Selectable<C,E> convert(Selectable<? super Annotated<C>, E> s, Predicate<? super ExecutableElement> annotationElementInclusionPredicate) Deprecated, for removal: This API element is subject to removal in a future version.An experimental method that converts aSelectableacceptingAnnotated<AnnotatedConstruct>instances into aSelectableacceptingAnnotatedConstructinstances.- Type Parameters:
C- the criteria typeE- the element type- Parameters:
s- a non-nullSelectableacceptingAnnotated<AnnotatedConstruct>instancesannotationElementInclusionPredicate- aPredicatethat returnstrueif a givenExecutableElement, representing an annotation element, is to be included in comparison operations; may benullin which case it is as ife -> truewere supplied instead- Returns:
- a non-
null, determinateSelectableacceptingAnnotatedConstructinstances - Throws:
NullPointerException- ifsisnull- 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 tests its first argument to see if it is selected by its second argument. The selector is invoked repeatedly. If, for any given invocation, the first argument is selected, the selected element is added to the selection that is eventually returned as a sublist of the supplied
Collection. 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
-