Interface ElementPredicate

  • Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

    @FunctionalInterface
    public interface ElementPredicate
    Interface used to filter elements.
    Author:
    Damien Carbonne
    • Field Detail

      • ANY_ELEMENT

        static final ElementPredicate ANY_ELEMENT
        An element predicate that always returns true.
      • EMPTY_ELEMENT

        static final ElementPredicate EMPTY_ELEMENT
        An element predicate that returns true when the element is empty.
      • PURE_ELEMENT

        static final ElementPredicate PURE_ELEMENT
        An element predicate that returns true when the element is empty and has no attribute.
    • Method Detail

      • accepts

        boolean accepts​(Parent parent,
                        Element element)
        Returns true when an element must be kept.

        Element (and its parents) must have been created before this can be called.
        However, its children are not necessarily existing at time of filtering.

        Parameters:
        parent - The element parent.
        element - The element.
        Returns:
        True if element must be kept, false otherwise.
      • and

        default ElementPredicate and​(ElementPredicate other)
        Returns a predicate that is the logical and combination of this one and another one.
        Parameters:
        other - The other predicate.
        Returns:
        A predicate that is the logical and combination of this one and other.
        Throws:
        IllegalArgumentException - When other is null.
      • or

        default ElementPredicate or​(ElementPredicate other)
        Returns a predicate that is the logical or combination of this one and another one.
        Parameters:
        other - The other predicate.
        Returns:
        A predicate that is the logical or combination of this one and other.
        Throws:
        IllegalArgumentException - When other is null.
      • fromNames

        static ElementPredicate fromNames​(Collection<String> names)
        Returns a predicate that returns true when the element name belongs to a collection.

        It is advised to use an efficient collection, typically a Set.

        Parameters:
        names - The collection of accepted names.
        Returns:
        A predicate that returns true when the element name belongs names.
        Throws:
        IllegalArgumentException - When names is null.