Class NodeTest

    • Constructor Summary

      Constructors 
      Constructor Description
      NodeTest()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      NodeTest copy()
      Copy a NodeTest.
      java.util.Optional<java.lang.String> explainMismatch​(Item item, TypeHierarchy th)
      Get extra diagnostic information about why a supplied item does not conform to this item type, if available.
      AtomicType getAtomizedItemType()
      Get the item type of the atomic values that will be produced when an item of this type is atomized (assuming that atomization succeeds)
      java.lang.String getBasicAlphaCode()
      Get an alphabetic code representing the type, or at any rate, the nearest built-in type from which this type is derived.
      SchemaType getContentType()
      Get the content type allowed by this NodeTest (that is, the type annotation of the matched nodes).
      abstract double getDefaultPriority()
      Determine the default priority to use if this node-test appears as a match pattern for a template with no explicit priority attribute.
      int getFingerprint()
      Get the name of the nodes matched by this nodetest, if it matches a specific name.
      Genre getGenre()
      Determine the Genre (top-level classification) of this type
      IntPredicateProxy getMatcher​(NodeVectorTree tree)
      Get a matching function that can be used to test whether numbered nodes in a TinyTree or DominoTree satisfy the node test.
      StructuredQName getMatchingNodeName()
      Get the name of the nodes matched by this nodetest, if it matches a specific name.
      ItemType getPrimitiveItemType()
      Get the primitive item type corresponding to this item type.
      int getPrimitiveType()
      Get the basic kind of object that this ItemType matches: for a NodeTest, this is the kind of node, or Type.Node if it matches different kinds of nodes.
      java.util.Optional<IntSet> getRequiredNodeNames()
      Get the set of node names allowed by this NodeTest.
      boolean isAtomicType()
      Determine whether this item type is an atomic type
      boolean isAtomizable​(TypeHierarchy th)
      Ask whether values of this type are atomizable
      boolean isNillable()
      Determine whether the content type (if present) is nillable
      boolean isPlainType()
      Determine whether this item type is atomic (that is, whether it can ONLY match atomic values)
      abstract boolean matches​(int nodeKind, NodeName name, SchemaType annotation)
      Test whether this node test is satisfied by a given node.
      boolean matches​(Item item, TypeHierarchy th)
      Test whether a given item conforms to this type
      SequenceType one()
      Get a sequence type representing exactly one instance of this atomic type
      SequenceType oneOrMore()
      Get a sequence type representing one or more instances of this atomic type
      boolean test​(NodeInfo node)
      Test whether this node test is satisfied by a given node.
      java.lang.String toShortString()  
      SequenceType zeroOrMore()
      Get a sequence type representing one or more instances of this atomic type
      SequenceType zeroOrOne()
      Get a sequence type representing zero or one instances of this atomic type
      • Methods inherited from class java.lang.Object

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

      • NodeTest

        public NodeTest()
    • Method Detail

      • getGenre

        public Genre getGenre()
        Determine the Genre (top-level classification) of this type
        Specified by:
        getGenre in interface ItemType
        Returns:
        the Genre to which this type belongs, specifically Genre.NODE
      • getDefaultPriority

        public abstract double getDefaultPriority()
        Determine the default priority to use if this node-test appears as a match pattern for a template with no explicit priority attribute.
        Specified by:
        getDefaultPriority in interface ItemType
        Returns:
        the default priority for the pattern
      • matches

        public boolean matches​(Item item,
                               TypeHierarchy th)
        Description copied from interface: ItemType
        Test whether a given item conforms to this type
        Specified by:
        matches in interface ItemType
        Parameters:
        item - The item to be tested
        th - The type hierarchy cache. Currently used only when matching function items.
        Returns:
        true if the item is an instance of this type; false otherwise
      • getPrimitiveItemType

        public ItemType getPrimitiveItemType()
        Get the primitive item type corresponding to this item type. For item(), this is Type.ITEM. For node(), it is Type.NODE. For specific node kinds, it is the value representing the node kind, for example Type.ELEMENT. For anyAtomicValue it is Type.ATOMIC_VALUE. For numeric it is Type.NUMBER. For other atomic types it is the primitive type as defined in XML Schema, except that INTEGER is considered to be a primitive type.
        Specified by:
        getPrimitiveItemType in interface ItemType
        Returns:
        the corresponding primitive type
      • getPrimitiveType

        public int getPrimitiveType()
        Get the basic kind of object that this ItemType matches: for a NodeTest, this is the kind of node, or Type.Node if it matches different kinds of nodes.
        Specified by:
        getPrimitiveType in interface ItemType
        Returns:
        the node kind matched by this node test
      • getFingerprint

        public int getFingerprint()
        Get the name of the nodes matched by this nodetest, if it matches a specific name. Return -1 if the node test matches nodes of more than one name
      • getMatchingNodeName

        public StructuredQName getMatchingNodeName()
        Get the name of the nodes matched by this nodetest, if it matches a specific name. Return null if the node test matches nodes of more than one name
      • getBasicAlphaCode

        public java.lang.String getBasicAlphaCode()
        Get an alphabetic code representing the type, or at any rate, the nearest built-in type from which this type is derived. The codes are designed so that for any two built-in types A and B, alphaCode(A) is a prefix of alphaCode(B) if and only if A is a supertype of B.
        Specified by:
        getBasicAlphaCode in interface ItemType
        Returns:
        the alphacode for the nearest containing built-in type
      • isAtomicType

        public boolean isAtomicType()
        Determine whether this item type is an atomic type
        Specified by:
        isAtomicType in interface ItemType
        Returns:
        true if this is ANY_ATOMIC_TYPE or a subtype thereof
      • isPlainType

        public boolean isPlainType()
        Determine whether this item type is atomic (that is, whether it can ONLY match atomic values)
        Specified by:
        isPlainType in interface ItemType
        Returns:
        false: this is not ANY_ATOMIC_TYPE or a subtype thereof
      • getAtomizedItemType

        public AtomicType getAtomizedItemType()
        Get the item type of the atomic values that will be produced when an item of this type is atomized (assuming that atomization succeeds)
        Specified by:
        getAtomizedItemType in interface ItemType
        Returns:
        the best available item type of the atomic values that will be produced when an item of this type is atomized, or null if it is known that atomization will throw an error.
      • isAtomizable

        public boolean isAtomizable​(TypeHierarchy th)
        Ask whether values of this type are atomizable
        Specified by:
        isAtomizable in interface ItemType
        Parameters:
        th - The type hierarchy cache
        Returns:
        true unless it is known that these items will be elements with element-only content, in which case return false
      • getMatcher

        public IntPredicateProxy getMatcher​(NodeVectorTree tree)
        Get a matching function that can be used to test whether numbered nodes in a TinyTree or DominoTree satisfy the node test. (Calling this matcher must give the same result as calling matchesNode(tree.getNode(nodeNr)), but it may well be faster).
        Parameters:
        tree - the tree against which the returned function will operate
        Returns:
        an IntPredicate; the matches() method of this predicate takes a node number as input, and returns true if and only if the node identified by this node number matches the node test.
      • matches

        public abstract boolean matches​(int nodeKind,
                                        NodeName name,
                                        SchemaType annotation)
        Test whether this node test is satisfied by a given node. This method is only fully supported for a subset of NodeTests, because it doesn't provide all the information needed to evaluate all node tests. In particular (a) it can't be used to evaluate a node test of the form element(N,T) or schema-element(E) where it is necessary to know whether the node is nilled, and (b) it can't be used to evaluate a node test of the form document-node(element(X)). This in practice means that it is used (a) to evaluate the simple node tests found in the XPath 1.0 subset used in XML Schema, and (b) to evaluate node tests where the node kind is known to be an attribute.
        Parameters:
        nodeKind - The kind of node to be matched
        name - identifies the expanded name of the node to be matched. The value should be null for a node with no name.
        annotation - The actual content type of the node. Null means no constraint.
        Returns:
        true if the node matches this node test
      • test

        public boolean test​(NodeInfo node)
        Test whether this node test is satisfied by a given node. This alternative method is used in the case of nodes where calculating the fingerprint is expensive, for example DOM or JDOM nodes. The default implementation calls the method matches(int, NodeName, SchemaType)
        Specified by:
        test in interface NodePredicate
        Parameters:
        node - the node to be matched
        Returns:
        true if the node test is satisfied by the supplied node, false otherwise
      • getContentType

        public SchemaType getContentType()
        Get the content type allowed by this NodeTest (that is, the type annotation of the matched nodes). Return AnyType if there are no restrictions. The default implementation returns AnyType.
        Returns:
        the type annotation that all nodes matching this NodeTest must satisfy
      • getRequiredNodeNames

        public java.util.Optional<IntSet> getRequiredNodeNames()
        Get the set of node names allowed by this NodeTest. This is returned as a set of Integer fingerprints. If all names are permitted (i.e. there are no constraints on the node name), returns IntUniversalSet.getInstance(). The default implementation returns the universal set.
        Returns:
        the set of integer fingerprints of the node names that this node test can match; or absent if the set of names cannot be represented (for example, with the name tests *:xxx or xxx:*)
      • isNillable

        public boolean isNillable()
        Determine whether the content type (if present) is nillable
        Returns:
        true if the content test (when present) can match nodes that are nilled
      • copy

        public NodeTest copy()
        Copy a NodeTest. Since they are never written to except in their constructors, returns the same.
        Returns:
        the original nodeTest
      • one

        public SequenceType one()
        Get a sequence type representing exactly one instance of this atomic type
        Specified by:
        one in interface ItemTypeWithSequenceTypeCache
        Returns:
        a sequence type representing exactly one instance of this atomic type
        Since:
        9.8.0.2
      • zeroOrOne

        public SequenceType zeroOrOne()
        Get a sequence type representing zero or one instances of this atomic type
        Specified by:
        zeroOrOne in interface ItemTypeWithSequenceTypeCache
        Returns:
        a sequence type representing zero or one instances of this atomic type
        Since:
        9.8.0.2
      • oneOrMore

        public SequenceType oneOrMore()
        Get a sequence type representing one or more instances of this atomic type
        Specified by:
        oneOrMore in interface ItemTypeWithSequenceTypeCache
        Returns:
        a sequence type representing one or more instances of this atomic type
        Since:
        9.8.0.2
      • zeroOrMore

        public SequenceType zeroOrMore()
        Get a sequence type representing one or more instances of this atomic type
        Specified by:
        zeroOrMore in interface ItemTypeWithSequenceTypeCache
        Returns:
        a sequence type representing one or more instances of this atomic type
        Since:
        9.8.0.2
      • explainMismatch

        public java.util.Optional<java.lang.String> explainMismatch​(Item item,
                                                                    TypeHierarchy th)
        Get extra diagnostic information about why a supplied item does not conform to this item type, if available. If extra information is returned, it should be in the form of a complete sentence, minus the closing full stop. No information should be returned for obvious cases.
        Specified by:
        explainMismatch in interface ItemType
        Parameters:
        item - the item that doesn't match this type
        th - the type hierarchy cache
        Returns:
        optionally, a message explaining why the item does not match the type
      • toShortString

        public java.lang.String toShortString()