Interface Filter<T,​U>

  • Type Parameters:
    T - the type of the object against which the predicate has to be played.
    U - the type of the object that is passed to the operation if its corresponding predicate is true.
    All Known Implementing Classes:
    FilterByType

    public interface Filter<T,​U>
    A filter is an object that plays all the predicates against a given object and that applies the operation associated with the matched predicate. If the object is an Optional or a Mutable instance, then the predicates are directly applied to the contained object; if they are empty, then no predicates are played.

    With a chain of match(Predicate, Consumer) methods, the operations are performed for each predicate that is true; the corresponding operations are performed in the order the matching rules are declared.

    With a chain of matchFirst(Predicate, Function) methods, only the operation of the first predicate that is true is executed.

    Author:
    mmoquillon
    • Method Detail

      • match

        Filter<T,​U> match​(Predicate<T> predicate,
                                Consumer<U> operation)
        Plays the specified predicate against an underlying object and applies the specified operation if and only if the predicate is true.
        Parameters:
        predicate - the predicate to match.
        operation - the operation associated with the predicate.
        Returns:
        itself.
      • matchFirst

        <V> FilterMatcher<T,​U,​V> matchFirst​(Predicate<T> predicate,
                                                        Function<U,​V> function)
        Plays the specified predicate against an underlying object and applies the specified function if and only if the predicate is true. If the predicate is true, the result of the function is stored in order to be retrieved later and the chain of predicate to play is stopped; the next predicates won't be played and hence their associated functions won't be executed. The result of the function mustn't be null otherwise an AssertionError is thrown.
        Type Parameters:
        V - the return type of the function.
        Parameters:
        predicate - the predicate to match.
        function - the function associated with the predicate and that returns a non-null computation result.
        Returns:
        a FilterMatcher instance from which the result can be retrieved and with which other filtering rules can be set.