Class Predicates


  • public class Predicates
    extends java.lang.Object
    This non-instantiable class provides a number of useful implementations of the Predicate interface, designed for use when navigating streams of XDM items.
    • Constructor Summary

      Constructors 
      Constructor Description
      Predicates()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.function.Predicate<XdmNode> attributeEq​(java.lang.String local, java.lang.String value)
      Obtain a predicate that tests whether an item is an element node with a given attribute (whose name is in no namespace) whose string value is equal to a given value
      static <T extends XdmItem>
      java.util.function.Predicate<XdmItem>
      empty​(Step<T> step)
      Obtain a predicate that tests whether a supplied Step delivers an empty result
      static java.util.function.Predicate<XdmItem> eq​(java.lang.String value)
      Obtain a predicate that tests whether the result of applying the XPath string() function to an item is equal to a given string
      static <T extends XdmItem>
      java.util.function.Predicate<XdmItem>
      eq​(Step<T> step, java.lang.String value)
      Obtain a predicate that tests whether there is some item in the result of applying a step, whose string value is equal to a given string.
      static java.util.function.Predicate<XdmAtomicValue> eq​(XdmAtomicValue value)
      Obtain a predicate that tests whether an atomic value compares equal to a supplied atomic value of a comparable type
      static <T extends XdmItem>
      java.util.function.Predicate<XdmItem>
      every​(Step<T> step, java.util.function.Predicate<? super XdmItem> condition)
      Obtain a predicate that tests whether every item in the result of applying a step satisfies the supplied condition.
      static <T extends XdmItem>
      java.util.function.Predicate<XdmItem>
      exists​(Step<T> step)
      Obtain a predicate that tests whether a supplied Step delivers a non-empty result
      static java.util.function.Predicate<XdmNode> hasAttribute​(java.lang.String local)
      Obtain a predicate that tests whether an item is an element node with a given attribute (whose name is in no namespace)
      static java.util.function.Predicate<XdmNode> hasLocalName​(java.lang.String localName)
      Obtain a predicate that tests whether an item is a node with a given local name, irrespective of the namespace
      static java.util.function.Predicate<? super XdmNode> hasName​(java.lang.String uri, java.lang.String localName)
      Obtain a predicate that tests whether an item is a node with a given namespace URI and local name
      static java.util.function.Predicate<XdmNode> hasNamespace​(java.lang.String uri)
      Obtain a predicate that tests whether an item is a node with a given namespace URI
      static java.util.function.Predicate<XdmItem> hasType​(ItemType type)
      Obtain a predicate that tests whether an item matches a given item type
      static java.util.function.Predicate<XdmItem> isArray()
      A predicate to test whether an item is an XDM array
      static java.util.function.Predicate<XdmItem> isAtomic()
      A predicate to test whether an item is an atomic value
      static java.util.function.Predicate<XdmItem> isAttribute()
      A predicate to test whether an item is an attribute node
      static java.util.function.Predicate<XdmItem> isComment()
      A predicate to test whether an item is a comment node
      static java.util.function.Predicate<XdmItem> isDocument()
      A predicate to test whether an item is a document node
      static java.util.function.Predicate<XdmItem> isElement()
      A predicate to test whether an item is an element node
      static java.util.function.Predicate<XdmItem> isFunction()
      A predicate to test whether an item is a function value (this includes maps and arrays)
      static java.util.function.Predicate<XdmItem> isMap()
      A predicate to test whether an item is an XDM map
      static java.util.function.Predicate<XdmItem> isNamespace()
      A predicate to test whether an item is a namespace node
      static java.util.function.Predicate<XdmItem> isNode()
      A predicate to test whether an item is a node
      static java.util.function.Predicate<XdmItem> isProcessingInstruction()
      A predicate to test whether an item is a processing instruction node
      static java.util.function.Predicate<XdmItem> isText()
      A predicate to test whether an item is a text node
      static java.util.function.Predicate<XdmItem> matchesRegex​(java.lang.String regex)
      Obtain a predicate that tests whether the result of applying the XPath string() function to an item matches a given regular expression
      static <T> java.util.function.Predicate<T> not​(java.util.function.Predicate<T> condition)
      Return a Predicate that is the negation of a supplied Predicate
      static <T extends XdmItem>
      java.util.function.Predicate<XdmItem>
      some​(Step<T> step, java.util.function.Predicate<? super T> condition)
      Obtain a predicate that tests whether there is some item in the result of applying a step that satisfies the supplied condition.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Predicates

        public Predicates()
    • Method Detail

      • isNode

        public static java.util.function.Predicate<XdmItem> isNode()
        A predicate to test whether an item is a node
        Returns:
        a predicate that returns true if given an item that is a node
      • isElement

        public static java.util.function.Predicate<XdmItem> isElement()
        A predicate to test whether an item is an element node
        Returns:
        a predicate that returns true if given an item that is an element node
      • isAttribute

        public static java.util.function.Predicate<XdmItem> isAttribute()
        A predicate to test whether an item is an attribute node
        Returns:
        a predicate that returns true if given an item that is an attribute node
      • isText

        public static java.util.function.Predicate<XdmItem> isText()
        A predicate to test whether an item is a text node
        Returns:
        a predicate that returns true if given an item that is a text node
      • isComment

        public static java.util.function.Predicate<XdmItem> isComment()
        A predicate to test whether an item is a comment node
        Returns:
        a predicate that returns true if given an item that is a comment node
      • isProcessingInstruction

        public static java.util.function.Predicate<XdmItem> isProcessingInstruction()
        A predicate to test whether an item is a processing instruction node
        Returns:
        a predicate that returns true if given an item that is a processing instruction node
      • isDocument

        public static java.util.function.Predicate<XdmItem> isDocument()
        A predicate to test whether an item is a document node
        Returns:
        a predicate that returns true if given an item that is a document node
      • isNamespace

        public static java.util.function.Predicate<XdmItem> isNamespace()
        A predicate to test whether an item is a namespace node
        Returns:
        a predicate that returns true if given an item that is a namespace node
      • isAtomic

        public static java.util.function.Predicate<XdmItem> isAtomic()
        A predicate to test whether an item is an atomic value

        Note: to test for a specific type of atomic value, use a predicate such as hasType(ItemType.XS_INTEGER)

        Returns:
        a predicate that returns true if given an item that is an atomic value.
      • isFunction

        public static java.util.function.Predicate<XdmItem> isFunction()
        A predicate to test whether an item is a function value (this includes maps and arrays)
        Returns:
        a predicate that returns true if given an item that is a function, including maps and arrays
      • isMap

        public static java.util.function.Predicate<XdmItem> isMap()
        A predicate to test whether an item is an XDM map
        Returns:
        a predicate that returns true if given an item that is a map
      • isArray

        public static java.util.function.Predicate<XdmItem> isArray()
        A predicate to test whether an item is an XDM array
        Returns:
        a predicate that returns true if given an item that is an array
      • empty

        public static <T extends XdmItem> java.util.function.Predicate<XdmItem> empty​(Step<T> step)
        Obtain a predicate that tests whether a supplied Step delivers an empty result
        Type Parameters:
        T - the type of items returned by the step
        Parameters:
        step - a step to be applied to the item being tested
        Returns:
        a predicate that returns true if the supplied step returns an empty result. For example empty(attribute("id") is a predicate that returns true for a node that has no "id" attribute. Similarly CHILD.where(empty(child(IS_ELEMENT))) is a step that selects child elements having no element children.
      • not

        public static <T> java.util.function.Predicate<T> not​(java.util.function.Predicate<T> condition)
        Return a Predicate that is the negation of a supplied Predicate
        Type Parameters:
        T - The type of object to which the predicate is applicable
        Parameters:
        condition - the supplied predicate
        Returns:
        a Predicate that matches an item if and only if the supplied Predicate does not match the item.
      • exists

        public static <T extends XdmItem> java.util.function.Predicate<XdmItem> exists​(Step<T> step)
        Obtain a predicate that tests whether a supplied Step delivers a non-empty result
        Type Parameters:
        T - the type of items returned by the step
        Parameters:
        step - a step to be applied to the item being tested
        Returns:
        a predicate that returns true if the step returns a non-empty result. For example exists(attribute("id") is a predicate that returns true for a node that has an "id" attribute. So CHILD.where(exists(attribute("id")) is a step that selects child elements having an "id" attribute.
      • hasName

        public static java.util.function.Predicate<? super XdmNode> hasName​(java.lang.String uri,
                                                                            java.lang.String localName)
        Obtain a predicate that tests whether an item is a node with a given namespace URI and local name
        Parameters:
        uri - the required namespace URI: supply a zero-length string to indicate the null namespace
        localName - the required local name
        Returns:
        a predicate that returns true if and only if the supplied item is a node with the given namespace URI and local name
      • hasLocalName

        public static java.util.function.Predicate<XdmNode> hasLocalName​(java.lang.String localName)
        Obtain a predicate that tests whether an item is a node with a given local name, irrespective of the namespace
        Parameters:
        localName - the required local name. If a zero-length string is supplied, the predicate will match nodes having no name (for example, comments and text nodes)
        Returns:
        a predicate that returns true if and only if the supplied item is a node with the given local name, irrespective of the namespace
      • hasNamespace

        public static java.util.function.Predicate<XdmNode> hasNamespace​(java.lang.String uri)
        Obtain a predicate that tests whether an item is a node with a given namespace URI
        Parameters:
        uri - the required namespace URI: supply a zero-length string to identify the null namespace
        Returns:
        a predicate that returns true if and only if the supplied item is a node with the given namespace URI. If a zero-length string is supplied, the predicate will also match nodes having no name, such as text and comment nodes, and nodes having a local name only, such as namespace and processing-instruction nodes.
      • hasAttribute

        public static java.util.function.Predicate<XdmNode> hasAttribute​(java.lang.String local)
        Obtain a predicate that tests whether an item is an element node with a given attribute (whose name is in no namespace)
        Parameters:
        local - the required attribute name
        Returns:
        a predicate that returns true if and only if the supplied item is an element having an attribute with the given local name, in no namespace
      • attributeEq

        public static java.util.function.Predicate<XdmNode> attributeEq​(java.lang.String local,
                                                                        java.lang.String value)
        Obtain a predicate that tests whether an item is an element node with a given attribute (whose name is in no namespace) whose string value is equal to a given value
        Parameters:
        local - the required attribute name
        value - the required attribute value
        Returns:
        a predicate that returns true if and only if the supplied item is an element having an attribute with the given local name, in no namespace, whose string value is equal to the given value
      • hasType

        public static java.util.function.Predicate<XdmItem> hasType​(ItemType type)
        Obtain a predicate that tests whether an item matches a given item type
        Parameters:
        type - the required item type
        Returns:
        a predicate that returns true if and only if the supplied item matches the supplied item type. For example, hasType(ItemType.DATE_TIME) matches atomic values of type xs:dateTime.
      • some

        public static <T extends XdmItem> java.util.function.Predicate<XdmItem> some​(Step<T> step,
                                                                                     java.util.function.Predicate<? super T> condition)
        Obtain a predicate that tests whether there is some item in the result of applying a step that satisfies the supplied condition.

        For example, some(CHILD, exists(attribute("foo")) matches an element if it has a child element with an attribute whose local name is "foo".

        If the step returns an empty sequence the result will always be false.

        Type Parameters:
        T - the type of items returned by the step
        Parameters:
        step - the step to be evaluated
        condition - the predicate to be applied to the items returned by the step
        Returns:
        a predicate that is true if at least one item selected by the step matches the supplied condition
      • every

        public static <T extends XdmItem> java.util.function.Predicate<XdmItem> every​(Step<T> step,
                                                                                      java.util.function.Predicate<? super XdmItem> condition)
        Obtain a predicate that tests whether every item in the result of applying a step satisfies the supplied condition.

        For example, every(CHILD, exists(attribute("foo")) matches an element if each of its child elements has an attribute whose local name is "foo".

        If the step returns an empty sequence the result will always be true.

        Type Parameters:
        T - the type of items returned by the step
        Parameters:
        step - the step to be evaluated
        condition - the predicate to be applied to the items returned by the step
        Returns:
        a predicate that is true if every item selected by the step matches the supplied condition
      • eq

        public static java.util.function.Predicate<XdmAtomicValue> eq​(XdmAtomicValue value)
        Obtain a predicate that tests whether an atomic value compares equal to a supplied atomic value of a comparable type
        Parameters:
        value - the atomic value to be compared with
        Returns:
        a Predicate which returns true when applied to a value that is equal to the supplied value under the "is-same-key" comparison rules. (These are the rules used to compare key values in an XDM map. The rules are chosen to be context-free, error-free, and transitive.)
      • eq

        public static java.util.function.Predicate<XdmItem> eq​(java.lang.String value)
        Obtain a predicate that tests whether the result of applying the XPath string() function to an item is equal to a given string
        Parameters:
        value - the string being tested
        Returns:
        a Predicate which returns true if the string value of the item being tested is equal to the given string under Java comparison rules for comparing strings.
      • matchesRegex

        public static java.util.function.Predicate<XdmItem> matchesRegex​(java.lang.String regex)
        Obtain a predicate that tests whether the result of applying the XPath string() function to an item matches a given regular expression
        Parameters:
        regex - the regular expression (this is a Java regular expression, not an XPath regular expression)
        Returns:
        a Predicate which returns true if the string value of the item being tested contains a substring that matches the given regular expression. To test the string in its entirety, use anchors "^" and "$" in the regular expression.
      • eq

        public static <T extends XdmItem> java.util.function.Predicate<XdmItem> eq​(Step<T> step,
                                                                                   java.lang.String value)
        Obtain a predicate that tests whether there is some item in the result of applying a step, whose string value is equal to a given string.

        For example, eq(attribute("id"), "foo") matches an element if it has an "id" attribute whose value is "foo".

        Type Parameters:
        T - the type of items to which the step applies
        Parameters:
        step - the step to be evaluated
        value - the string to be compared against the items returned by the step
        Returns:
        a Predicate which returns true if some item selected by the step has as string value equal to the given string