Class Predicates

java.lang.Object
net.sf.saxon.s9api.streams.Predicates

public class Predicates extends 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 Details

    • Predicates

      public Predicates()
  • Method Details

    • isNode

      public static 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 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 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 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 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 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 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 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 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 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 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 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> 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> Predicate<T> not(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> 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 Predicate<? super XdmNode> hasName(String uri, 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 Predicate<XdmNode> hasLocalName(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 Predicate<XdmNode> hasNamespace(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 Predicate<XdmNode> hasAttribute(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 Predicate<XdmNode> attributeEq(String local, 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 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> Predicate<XdmItem> some(Step<T> step, 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> Predicate<XdmItem> every(Step<T> step, 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 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 Predicate<XdmItem> eq(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 Predicate<XdmItem> matchesRegex(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> Predicate<XdmItem> eq(Step<T> step, 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