Class ChoiceItemType

java.lang.Object
net.sf.saxon.type.ChoiceItemType
All Implemented Interfaces:
ChoiceType, ItemType
Direct Known Subclasses:
LocalUnionType

public class ChoiceItemType extends Object implements ItemType, ChoiceType
A class that represents a union type declared locally, for example using the XPath 4.0 choice item-type syntax (a|b|c), or internally in Java code.
  • Field Details

    • memberTypes

      protected final List<? extends ItemType> memberTypes
    • CHOICE_OF_ANY

      public static final ChoiceItemType CHOICE_OF_ANY
    • CHOICE_OF_GNODE

      public static final ChoiceItemType CHOICE_OF_GNODE
    • CHOICE_OF_XNODE

      public static final ChoiceItemType CHOICE_OF_XNODE
    • CHOICE_OF_ATOMIC

      public static final ChoiceItemType CHOICE_OF_ATOMIC
  • Constructor Details

    • ChoiceItemType

      public ChoiceItemType(List<? extends ItemType> memberTypes)
      Creates a new ChoiceItemType.
      Parameters:
      memberTypes - the atomic member types of the union
  • Method Details

    • makeChoiceItemType

      public static ItemType makeChoiceItemType(List<ItemType> memberTypes)
    • of

      public static ChoiceItemType of(ItemType... memberTypes)
    • of

      public static ChoiceItemType of(UType uType)
    • getMemberTypes

      public List<? extends ItemType> getMemberTypes()
      Get the alternative member types as a list
      Returns:
      the alternatives making up this choice type
    • getAlternatives

      public Iterable<? extends ItemType> getAlternatives()
      Description copied from interface: ChoiceType
      Get the alternative types available within this choice types
      Specified by:
      getAlternatives in interface ChoiceType
      Returns:
      the alternative item types
    • getGenre

      public Genre getGenre()
      Get the genre of this item type
      Specified by:
      getGenre in interface ItemType
      Returns:
      the genre
    • getDescription

      public String getDescription()
    • isAtomicType

      public boolean isAtomicType()
      Ask whether this Simple Type is an atomic type
      Specified by:
      isAtomicType in interface ItemType
      Returns:
      false, this is not an atomic type
    • isPlainType

      public boolean isPlainType()
      Ask whether this Union type is a "plain type", defined as a union type whose member types are all atomic types or plain unions. That is, it disallows unions that are derived by restriction from another union. The significance of this is that an atomic value will never match a non-plain union type
      Specified by:
      isPlainType in interface ItemType
      Returns:
      true if this is ANY_ATOMIC_TYPE or a subtype thereof, or a "plain" union type (that is, unions of atomic types that impose no further restrictions). Return false if this is a union type whose member types are not all known.
    • someMemberTypeSatisfies

      public boolean someMemberTypeSatisfies(Predicate<? super ItemType> condition)
      Ask whether there is an alternative in the choice type that satisfies a given condition
      Parameters:
      condition - the given condition
      Returns:
      true if a matching alternative is found
    • eliminating

      public ItemType eliminating(Predicate<? super ItemType> condition)
      Return an item type that eliminates one (or more) of the alternatives
      Parameters:
      condition - predicate determining which alternatives to drop
      Returns:
      an ItemType that eliminates the selected choices
    • isBuiltInType

      public boolean isBuiltInType()
      Determine whether this is a built-in type or a user-defined type
    • isListType

      public boolean isListType()
      Determine whether this is a list type
    • isUnionType

      public boolean isUnionType()
      Return true if this type is a union type (that is, if its variety is union)
      Returns:
      true for a union type
    • getUType

      public UType getUType()
      Get the corresponding UType. A UType is a union of primitive item types.
      Specified by:
      getUType in interface ItemType
      Returns:
      the smallest UType that subsumes this item 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
    • matches

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

      public ItemType getPrimitiveItemType()
      Method defined in ItemType: get a primitive supertype in the ItemType type hierarchy
      Specified by:
      getPrimitiveItemType in interface ItemType
      Returns:
      BuiltInAtomicType.ANY_ATOMIC
    • toMultipleNodeKindTest

      public MultipleNodeKindTest toMultipleNodeKindTest()
      Convert, if possible, to a multiple node kind test
      Returns:
      the equivalent MultipleNodeKindTest or null if there is no equivalent
    • getPrimitiveType

      public int getPrimitiveType()
      Method defined in ItemType: get a primitive supertype in the ItemType type hierarchy
      Specified by:
      getPrimitiveType in interface ItemType
      Returns:
      StandardNames.XS_ANY_ATOMIC_TYPE
    • getAtomizedItemType

      public PlainType getAtomizedItemType()
      Description copied from interface: ItemType
      Get the item type of the atomic values that will be produced when an item of this type is atomized
      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)
      Description copied from interface: ItemType
      Ask whether values of this type are atomizable
      Specified by:
      isAtomizable in interface ItemType
      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
    • getDefaultPriority

      public double getDefaultPriority()
      Get the default priority when this ItemType is used as an XSLT pattern
      Specified by:
      getDefaultPriority in interface ItemType
      Returns:
      the default priority. For a choice type this is defined as the maximum of the default priorities of the member types.
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • asChoiceItemType

      public ChoiceItemType asChoiceItemType()
      Description copied from interface: ItemType
      Expand this item type to a choice item type. The default delivers a choice with this type as its only member. Implementations for abstract types return a choice of the corresponding concrete types, for example node() expands to a choice of the seven node kinds. The implementation for a choice type that includes abstract member types should expand these recursively.
      Specified by:
      asChoiceItemType in interface ItemType
    • expand

      public ChoiceItemType expand()
    • toString

      public String toString()
      Produce a string representation of the type name. If the type is anonymous, an internally-allocated type name will be returned.
      Overrides:
      toString in class Object
      Returns:
      the name of the atomic type in the form Q{uri}local
    • toExportString

      public String toExportString()
      Description copied from interface: ItemType
      Return a string representation of this ItemType suitable for use in stylesheet export files. This differs from the result of toString() in that it will not contain any references to anonymous types. Note that it may also use the Saxon extended syntax for union types and tuple types. The default implementation returns the result of calling toString().
      Specified by:
      toExportString in interface ItemType
      Returns:
      the string representation as an instance of the XPath SequenceType construct
    • getCoercionPlan

      public CoercionPlan getCoercionPlan(int version)
      Get the coercion plan for use when this type is the required type for (say) coercion of arguments in a function call
      Specified by:
      getCoercionPlan in interface ItemType
      Parameters:
      version - the XPath language version (40 or 31)
    • explainMismatch

      public Optional<String> explainMismatch(Item item, TypeHierarchy th)
      Description copied from interface: ItemType
      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