- Type Parameters:
T- the type of objects to filterU- the objects' field on which to operate
- Direct Known Subclasses:
BooleanFilter,EnumFilter,NumberFilter,StringFilter
In other words, it is capable of extracting a field U from an object T (this is the extractor function)
and producing a Predicate given a certain input (also called query) and it's a String.
To make the filter system flexible and yet highly specialized, every implementation must specify a
StringConverter which is used to convert the query to an object of type U.
Predicate is predicate is produced.
Every implementation of this base class has some predefined BiPredicate which operate on U objects.
The query is converted to an object of type U, and the extractor gets the U field from a T object, both U
objects are fed to the BiPredicate. In code:
// We have the query...
String query = ...;
U convertedQuery = converter.fromString(query);
// We can build a Predicate<T> by doing this...
Predicate<T> predicate = t -> biPredicate.test(extractor.apply(t), convertedQuery);
Filters are intended to be used with UI controls, they provide an interactive way to build a Predicate
and filter a collection with generics, however you can also use them without an UI, however some other
aspects needs to be discussed because they are strictly related to UI usage:
Every filter has a name, see MFXFilterPane documentation for an example
BiPredicates are wrapped in a BiPredicateBean
The BiPredicate to use is "selected" with an index property (ideal for comboboxes), see predicateFor(String).
-
Property Summary
Properties -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final StringConverter<U>protected final ObservableList<BiPredicateBean<U,U>> protected final IntegerProperty -
Constructor Summary
ConstructorsConstructorDescriptionAbstractFilter(String name, Function<T, U> extractor, StringConverter<U> converter) -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract ObservableList<BiPredicateBean<U,U>> Every implementation ofAbstractFiltermust define some defaultBiPredicates.protected abstract AbstractFilter<T,U> extend(BiPredicateBean<U, U>... predicateBeans) Allows to add some extraBiPredicateBeans alongside the default ones.intGets the value of the property selectedPredicateIndex.Converts a given input String to an object of type U using theStringConverterspecified by this filter.name()predicateFor(String input) Produces aPredicatefrom the given input.predicateFor(String input, BiPredicate<U, U> biPredicate) Produces aPredicatefrom the given input andBiPredicate.Used to specify the selectedBiPredicateBean.voidsetSelectedPredicateIndex(int selectedPredicateIndex) Sets the value of the property selectedPredicateIndex.FilterBean<T,U> toFilterBean(String input) Converts this filter to aFilterBeanfrom the given input.FilterBean<T,U> toFilterBean(String input, BiPredicateBean<U, U> bean, ChainMode mode) FilterBean<T,U> toFilterBean(String input, ChainMode mode) Converts this filter to aFilterBeanfrom the given input andChainMode.toString()
-
Property Details
-
selectedPredicateIndex
Used to specify the selectedBiPredicateBean.
-
-
Field Details
-
predicates
-
selectedPredicateIndex
-
converter
-
-
Constructor Details
-
AbstractFilter
-
-
Method Details
-
defaultPredicates
Every implementation ofAbstractFiltermust define some defaultBiPredicates. -
extend
Allows to add some extraBiPredicateBeans alongside the default ones. -
getValue
Converts a given input String to an object of type U using theStringConverterspecified by this filter. -
predicateFor
Produces aPredicatefrom the given input. First checks if aBiPredicateis selected by checking the selected index property, seecheckIndex().Then converts the input to an object of type U by using
In code:getValue(String), and then returns a Predicate that applies the selected BiPredicate to the extracted U field of T and the converted U input.return t -> biPredicate.test(extractor.apply(t), convertedQuery); -
predicateFor
Produces aPredicatefrom the given input andBiPredicate. First converts the input to an object of type U by usinggetValue(String), and then returns a Predicate that applies the given BiPredicate to the extracted U field of T and the converted U input. In code:
WARN: to be honest this method should have been removed but I wanted to keep it since it adds some flexibility to the filter system. Note that using this method may lead to inconsistencies in UI controls since the given argument is not areturn t -> biPredicate.test(extractor.apply(t), convertedQuery);BiPredicateBean, which means that it won't be added to the predicates list of this filter, and the selected predicate index property won't be updated. This also means that any other method that relies on that index will fail. -
toFilterBean
Converts this filter to aFilterBeanfrom the given input. Checks for the selected BiPredicate, seecheckIndex(). -
toFilterBean
Converts this filter to aFilterBeanfrom the given input andChainMode. Checks for the selected BiPredicate, seecheckIndex(). -
toFilterBean
-
name
- Returns:
- the filter's name
-
getExtractor
- Returns:
- the function used to extract a field of type U from an object of type T
-
getPredicates
- Returns:
- the list of usable
BiPredicates, each wrapped in aBiPredicateBean
-
getSelectedPredicateIndex
public int getSelectedPredicateIndex()Gets the value of the property selectedPredicateIndex.- Property description:
- Used to specify the selected
BiPredicateBean.
-
selectedPredicateIndexProperty
Used to specify the selectedBiPredicateBean. -
setSelectedPredicateIndex
public void setSelectedPredicateIndex(int selectedPredicateIndex) Sets the value of the property selectedPredicateIndex.- Property description:
- Used to specify the selected
BiPredicateBean.
-
getConverter
- Returns:
- the
StringConverterused to convert the input String to an object of type U
-
toString
-