Class FilterByType

  • All Implemented Interfaces:
    Filter<Class<?>,​Object>

    public class FilterByType
    extends Object
    implements Filter<Class<?>,​Object>
    A filter by the type of the wrapped object. If the type of the object matches a given predicate then the operation with the matched predicate is performed against this object. The object cannot be null otherwise nothing is performed.
    Author:
    mmoquillon
    • Constructor Detail

      • FilterByType

        public FilterByType​(Object value)
        Constructs a filter by type on the specified value.
        Parameters:
        value - the value against which the predicates will be played. If the value is an Optional or a Mutable instance, then only its contained value is considered.
    • Method Detail

      • match

        public FilterByType match​(Predicate<Class<?>> predicate,
                                  Consumer<Object> operation)
        Description copied from interface: Filter
        Plays the specified predicate against an underlying object and applies the specified operation if and only if the predicate is true.
        Specified by:
        match in interface Filter<Class<?>,​Object>
        Parameters:
        predicate - the predicate to match.
        operation - the operation associated with the predicate.
        Returns:
        itself.
      • matchFirst

        public <V> FilterMatcher<Class<?>,​Object,​V> matchFirst​(Predicate<Class<?>> predicate,
                                                                           Function<Object,​V> function)
        Description copied from interface: Filter
        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.
        Specified by:
        matchFirst in interface Filter<Class<?>,​Object>
        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.