Interface TristateFilter<T>
- All Superinterfaces:
java.util.function.Function<T,TristateFilter.Policy>
- All Known Subinterfaces:
CycleResultTristateFilter
- All Known Implementing Classes:
EnumReadableMappingFilter,InputMapper,ResultFilteringSieve,ResultFilterPhase,ResultMappingArrayFilter
public interface TristateFilter<T> extends java.util.function.Function<T,TristateFilter.Policy>
A tri-state filter allows for flexible configuration of
multi-phase filtering. It effectively allows a conditional behavior
for filtering logic that can answer "yes", "no", and "I don't know."
This can also be used to build classic bi-state filtering, such as
filters that use a boolean predicate to say "keep" or "discard." Where the
tri-state filtering pattern shines, however, is in the ability to combine
different filtering rules to build a sophisticated filter at run-time
that bi-state filtering would prevent.
In contrast to the bi-state filter, the default policy that is applied when
not matching an item with the predicate is to simply ignore it.
This means that in order to implement both matching and discarding
policies like a bi-state filter, you must do one of the following:
- Implement a default policy that overrides the "Ignore" action.
- Use both "keep" and "discard" predicates together in sequence.
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classTristateFilter.DefaultingPredicate<T>static classTristateFilter.MatchingPredicate<T>static classTristateFilter.PolicyThe filter action determines what action is taken for a given element that matches the predicate. -
Method Summary
Modifier and Type Method Description TristateFilter.Policyapply(T cycleResult)default java.util.function.Predicate<T>toDefaultingPredicate(TristateFilter.Policy defaultPolicy)Create a predicate that will override any Ignore outcomes with the provided policy.default java.util.function.Predicate<T>toMatchingPredicate(TristateFilter.Policy matchingPolicy)Create a predicate that will return true if and only if the filter outcome matches the provided policy.
-
Method Details
-
apply
- Specified by:
applyin interfacejava.util.function.Function<T,TristateFilter.Policy>
-
toDefaultingPredicate
Create a predicate that will override any Ignore outcomes with the provided policy.- Parameters:
defaultPolicy- The policy that will override non-actionable outcomes- Returns:
- a Predicate that can be used to filter elements
-
toMatchingPredicate
Create a predicate that will return true if and only if the filter outcome matches the provided policy.- Parameters:
matchingPolicy- The policy that will signal true in the predicate.- Returns:
- a Predicate that can be used to filter elements
-