/** * Ask whether a given Item is an instance of this UType * @param item the item to be tested * @return true if this UType matches the supplied item */ public boolean matches(Item item) { return subsumes(getUType(item)); }
/** * Ask whether a given Item is an instance of this UType * @param item the item to be tested * @return true if this UType matches the supplied item */ public boolean matches(Item item) { return subsumes(getUType(item)); }
/** * Get the UType of the items in a sequence. If the sequence is heterogeneous, * the method returns the lowest common supertype. If the sequence is empty, it returns * ErrorType (the type to which no instance can belong) * * @param sequence the input sequence * @return the lowest common supertype of the types of the items in the sequence */ public static UType getUType(Sequence<?> sequence) { if (sequence instanceof Item) { return UType.getUType((Item) sequence); } else if (sequence instanceof GroundedValue) { UType type = UType.VOID; UnfailingIterator iter = ((GroundedValue) sequence).iterate(); Item item; while ((item = iter.next()) != null) { type = type.union(UType.getUType(item)); if (type == UType.ANY) { break; } } return type; } else { return UType.ANY; } }
/** * Get the UType of the items in a sequence. If the sequence is heterogeneous, * the method returns the lowest common supertype. If the sequence is empty, it returns * ErrorType (the type to which no instance can belong) * * @param sequence the input sequence * @return the lowest common supertype of the types of the items in the sequence */ public static UType getUType(Sequence<?> sequence) { if (sequence instanceof Item) { return UType.getUType((Item) sequence); } else if (sequence instanceof GroundedValue) { UType type = UType.VOID; UnfailingIterator iter = ((GroundedValue) sequence).iterate(); Item item; while ((item = iter.next()) != null) { type = type.union(UType.getUType(item)); if (type == UType.ANY) { break; } } return type; } else { return UType.ANY; } }
/** * Get the UType of a Sequence * @param sequence the sequence whose UType is required * @return the UType of the item */ public static UType getUType(GroundedValue sequence) { UnfailingIterator iter = sequence.iterate(); Item item; UType u = UType.VOID; while ((item = iter.next()) != null) { u = u.union(getUType(item)); } return u; }
/** * Get the UType of a Sequence * @param sequence the sequence whose UType is required * @return the UType of the item */ public static UType getUType(GroundedValue sequence) { UnfailingIterator iter = sequence.iterate(); Item item; UType u = UType.VOID; while ((item = iter.next()) != null) { u = u.union(getUType(item)); } return u; }
/** * 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. * * @param item the item that doesn't match this type * @param th the type hierarchy cache * @return optionally, a message explaining why the item does not match the type */ @Override public Optional<String> explainMismatch(Item item, TypeHierarchy th) { if (item instanceof NodeInfo) { UType actualKind = UType.getUType(item); if (!getUType().overlaps(actualKind)) { return Optional.of("The supplied value is " + actualKind.toStringWithIndefiniteArticle()); } return Optional.empty(); } else { return Optional.of("The supplied value is " + item.getGenre().getDescription()); } }
/** * 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. * * @param item the item that doesn't match this type * @param th the type hierarchy cache * @return optionally, a message explaining why the item does not match the type */ @Override public Optional<String> explainMismatch(Item item, TypeHierarchy th) { if (item instanceof NodeInfo) { UType actualKind = UType.getUType(item); if (!getUType().overlaps(actualKind)) { return Optional.of("The supplied value is " + actualKind.toStringWithIndefiniteArticle()); } return Optional.empty(); } else { return Optional.of("The supplied value is " + item.getGenre().getDescription()); } }
/** * 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. * * @param item the item that doesn't match this type * @param th the type hierarchy cache * @return optionally, a message explaining why the item does not match the type */ @Override public Optional<String> explainMismatch(Item item, TypeHierarchy th) { Optional<String> explanation = super.explainMismatch(item, th); if (explanation.isPresent()) { return explanation; } if (item instanceof NodeInfo) { UType actualKind = UType.getUType(item); if (!getUType().overlaps(actualKind)) { return Optional.of("The supplied value is " + actualKind.toStringWithIndefiniteArticle()); } else { return Optional.empty(); } } else { return Optional.of("The supplied value is " + item.getGenre().getDescription()); } }
/** * 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. * * @param item the item that doesn't match this type * @param th the type hierarchy cache * @return optionally, a message explaining why the item does not match the type */ @Override public Optional<String> explainMismatch(Item item, TypeHierarchy th) { Optional<String> explanation = super.explainMismatch(item, th); if (explanation.isPresent()) { return explanation; } if (item instanceof NodeInfo) { UType actualKind = UType.getUType(item); if (!getUType().overlaps(actualKind)) { return Optional.of("The supplied value is " + actualKind.toStringWithIndefiniteArticle()); } else { return Optional.empty(); } } else { return Optional.of("The supplied value is " + item.getGenre().getDescription()); } }
if (!reqItemType.matches(item, context.getConfiguration().getTypeHierarchy())) { XPathException err = new XPathException("Required type is " + reqItemType + "; supplied value has type " + UType.getUType(val.materialize())); err.setIsTypeError(true); err.setErrorCode("XPTY0004");
if (!reqItemType.matches(item, context.getConfiguration().getTypeHierarchy())) { XPathException err = new XPathException("Required type is " + reqItemType + "; supplied value has type " + UType.getUType(val.materialize())); err.setIsTypeError(true); err.setErrorCode("XPTY0004");