Class NodeKindType

All Implemented Interfaces:
NodePredicate, NodeTest, NodeVectorMatchMaker, ItemType, ItemTypeWithSequenceTypeCache

public class NodeKindType extends XNodeType implements NodeVectorMatchMaker
A NodeKindType matches one of the seven kinds of XNode.
  • Field Details

  • Method Details

    • getGenre

      public Genre getGenre()
      Determine the Genre (top-level classification) of this type
      Specified by:
      getGenre in interface ItemType
      Overrides:
      getGenre in class XNodeType
      Returns:
      the Genre to which this type belongs, for example node or atomic value
    • of

      public static NodeKindType of(int nodeKind)
    • getNodeKind

      public int getNodeKind()
      Get the node kind matched by this test
      Returns:
      the matching node kind
    • getAllowedNodeNames

      public QNameTest getAllowedNodeNames()
      Get the set of allowed node names that this type if capable of matching
      Specified by:
      getAllowedNodeNames in class XNodeType
      Returns:
      the allowed node names
    • getUType

      public UType getUType()
      Get the corresponding UType. A UType is a union of primitive item types.
      Specified by:
      getUType in interface ItemType
      Specified by:
      getUType in interface NodeTest
      Overrides:
      getUType in class XNodeType
      Returns:
      the smallest UType that subsumes this item type
    • makeNodeKindTest

      public static GNodeType makeNodeKindTest(int kind)
      Make a test for a given kind of node
    • 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).
      Specified by:
      getMatcher in interface NodeVectorMatchMaker
      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 predicate.
    • isAtomizable

      public boolean isAtomizable(TypeHierarchy th)
      Ask whether values of this type are atomizable
      Specified by:
      isAtomizable in interface ItemType
      Overrides:
      isAtomizable in class GNodeType
      Parameters:
      th - the type hierarchy cache
      Returns:
      true if some or all instances of this type can be successfully atomized; false if no instances of this type can be atomized
    • matches

      public boolean matches(Item item)
      Description copied from class: GNodeType
      Test whether a given item conforms to this type
      Specified by:
      matches in interface ItemType
      Specified by:
      matches in class GNodeType
      Parameters:
      item - The item to be tested
      Returns:
      true if the item is an instance of this type; false otherwise
    • getDefaultPriority

      public final double getDefaultPriority()
      Determine the default priority of this node test when used on its own as a Pattern
      Specified by:
      getDefaultPriority in interface ItemType
      Specified by:
      getDefaultPriority in interface NodeTest
      Returns:
      the default priority
    • getPrimitiveType

      public int getPrimitiveType()
      Determine the types of nodes to which this pattern applies. Used for optimisation.
      Specified by:
      getPrimitiveType in interface ItemType
      Overrides:
      getPrimitiveType in class GNodeType
      Returns:
      the type of node matched by this pattern. e.g. Type.ELEMENT or Type.TEXT
    • getAtomizedItemType

      public AtomicType getAtomizedItemType()
      Get the content type allowed by this NodeTest (that is, the type annotation). Return AnyType if there are no restrictions. The default implementation returns AnyType.
      Specified by:
      getAtomizedItemType in interface ItemType
      Overrides:
      getAtomizedItemType in class GNodeType
      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.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • describe

      public static String describe(int kind)
    • nodeKindName

      public static String nodeKindName(int kind)
      Get the name of a node kind
      Parameters:
      kind - the node kind, for example Type.ELEMENT or Type.ATTRIBUTE
      Returns:
      the name of the node kind, for example "element" or "attribute"
    • hashCode

      public int hashCode()
      Returns a hash code value for the object.
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object other)
      Indicates whether some other object is "equal to" this one.
      Overrides:
      equals in class Object
    • explainMismatch

      public Optional<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
      Specified by:
      explainMismatch in interface NodeTest
      Overrides:
      explainMismatch in class GNodeType
      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
    • getBasicAlphaCode

      public 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