@Override public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException { if (arguments.length > 0) { long most = (Long) SequenceTool.convertToJava(arguments[0].head()); long least = 0; if (arguments.length > 1) { least = (Long) SequenceTool.convertToJava(arguments[1].head()); } return StringValue.makeStringValue(new UUID(most, least).toString()); } return StringValue.makeStringValue(UUID.randomUUID().toString()); } };
private void makeSequence() throws XPathException { if (sequence == null) { inputIterator = expression.iterate(savedXPathContext); sequence = SequenceTool.toMemoSequence(inputIterator); } }
/** * Get a sequence type to which a given value conforms * @param value the given value * @param th the type hierarchy cache * @return the best available sequence type to which the supplied value conforms */ public static SequenceType getSequenceType(Sequence<?> value, TypeHierarchy th) { return SequenceType.makeSequenceType(getItemType(value, th), getCardinality(value)); }
/** * Get the string value of this sequence. The string value of an item is the result of applying the string() * function. The string value of a sequence is the space-separated result of applying the string-join() function * using a single space as the separator * * @return the string value of the sequence. * @throws net.sf.saxon.trans.XPathException * if the sequence contains items that have no string value (for example, function items) */ public CharSequence getStringValueCS() throws XPathException { return SequenceTool.getStringValue(this); }
ItemType suppliedItemType = SequenceTool.getItemType(value, this); return SequenceTool.toMemoSequence(iterator);
public Sequence<?> convert(Object object, XPathContext context) throws XPathException { List<Item<?>> list = new ArrayList<>(((Collection) object).size()); int a = 0; for (Object obj : (Collection) object) { JPConverter itemConverter = allocate(obj.getClass(), null, context.getConfiguration()); try { Item<?> item = SequenceTool.asItem(itemConverter.convert(obj, context)); if (item != null) { list.add(item); } } catch (XPathException e) { throw new XPathException( "Returned Collection contains an object that cannot be converted to an Item (" + obj.getClass() + "): " + e.getMessage(), SaxonErrorCode.SXJE0051); } } return new SequenceExtent<>(list); }
/** * Get the number of items in the sequence * * @return the number of items in the value, considered as a sequence. Note that for arrays * and maps, the answer will be 1 (one) since arrays and maps are items. * @throws SaxonApiUncheckedException if the value is lazily evaluated and the delayed * evaluation fails with a dynamic error. */ public int size() { try { return SequenceTool.getLength(value); } catch (XPathException err) { throw new SaxonApiUncheckedException(err); } }
/** * After adding an entry to the map, update the cached type information * @param key the new key * @param val the new associated value * @param wasEmpty true if the map was empty before adding these values */ private void updateTypeInformation(AtomicValue key, Sequence<?> val, boolean wasEmpty) { // if (Instrumentation.ACTIVE) { // Instrumentation.count("updateTypeInformation"); // } if (wasEmpty) { keyUType = key.getUType(); valueUType = SequenceTool.getUType(val); keyAtomicType = key.getItemType(); valueItemType = MapItem.getItemTypeOfSequence(val); valueCardinality = SequenceTool.getCardinality(val); } else { keyUType = keyUType.union(key.getUType()); valueUType = valueUType.union(SequenceTool.getUType(val)); valueCardinality = Cardinality.union(valueCardinality, SequenceTool.getCardinality(val)); if (key.getItemType() != keyAtomicType) { keyAtomicType = null; } if (!MapItem.isKnownToConform(val, valueItemType)) { valueItemType = null; } } }
} else { throw new XPathException("Cannot convert value " + value.getClass() + " of type " + SequenceTool.getItemType(value, context.getConfiguration().getTypeHierarchy()) + " to class " + targetClass.getName());
/** * Factory method to construct a CardinalityChecker. The method may create an expression that combines * the cardinality checking with the functionality of the underlying expression class * * @param sequence the base sequence whose cardinality is to be checked * @param cardinality the required cardinality * @param role information to be used in error reporting * @return a new Expression that does the CardinalityChecking (not necessarily a CardinalityChecker) */ public static Expression makeCardinalityChecker(Expression sequence, int cardinality, RoleDiagnostic role) { Expression result; if (sequence instanceof Literal && Cardinality.subsumes(cardinality, SequenceTool.getCardinality(((Literal) sequence).getValue()))) { return sequence; } if (sequence instanceof Atomizer && !Cardinality.allowsMany(cardinality)) { Expression base = ((Atomizer) sequence).getBaseExpression(); result = new SingletonAtomizer(base, role, Cardinality.allowsZero(cardinality)); } else { result = new CardinalityChecker(sequence, cardinality, role); } ExpressionTool.copyLocationInfo(sequence, result); return result; }
/** * Determine whether two sequences have the same number of items. This is more efficient * than comparing the counts, because the longer sequence is evaluated only as far as the * length of the shorter sequence. The method consumes the supplied iterators. * * @param a iterator over the first sequence * @param b iterator over the second sequece * @return true if the lengths of the two sequences are the same */ public static boolean sameLength(SequenceIterator a, SequenceIterator b) throws XPathException { if ((a.getProperties() & SequenceIterator.LAST_POSITION_FINDER) != 0) { return hasLength(b, ((LastPositionFinder) a).getLength()); } else if ((b.getProperties() & SequenceIterator.LAST_POSITION_FINDER) != 0) { return hasLength(a, ((LastPositionFinder) b).getLength()); } else { while (true) { Item itA = a.next(); Item itB = b.next(); if (itA == null || itB == null) { if (itA != null) { a.close(); } if (itB != null) { b.close(); } return itA == null && itB == null; } } } }
/** * Get the string value of this sequence. The string value of an item is the result of applying the string() * function. The string value of a sequence is the space-separated result of applying the string-join() function * using a single space as the separator * * @return the string value of the sequence. * @throws net.sf.saxon.trans.XPathException * if the sequence contains items that have no string value (for example, function items) */ public CharSequence getStringValueCS() throws XPathException { return SequenceTool.getStringValue(this); }
ItemType suppliedItemType = SequenceTool.getItemType(value, this); return SequenceTool.toMemoSequence(iterator);
public Sequence<?> convert(Object object, XPathContext context) throws XPathException { List<Item<?>> list = new ArrayList<>(((Collection) object).size()); int a = 0; for (Object obj : (Collection) object) { JPConverter itemConverter = allocate(obj.getClass(), null, context.getConfiguration()); try { Item<?> item = SequenceTool.asItem(itemConverter.convert(obj, context)); if (item != null) { list.add(item); } } catch (XPathException e) { throw new XPathException( "Returned Collection contains an object that cannot be converted to an Item (" + obj.getClass() + "): " + e.getMessage(), SaxonErrorCode.SXJE0051); } } return new SequenceExtent<>(list); }
/** * Get the number of items in the sequence * * @return the number of items in the value, considered as a sequence. Note that for arrays * and maps, the answer will be 1 (one) since arrays and maps are items. * @throws SaxonApiUncheckedException if the value is lazily evaluated and the delayed * evaluation fails with a dynamic error. */ public int size() { try { return SequenceTool.getLength(value); } catch (XPathException err) { throw new SaxonApiUncheckedException(err); } }
/** * After adding an entry to the map, update the cached type information * @param key the new key * @param val the new associated value * @param wasEmpty true if the map was empty before adding these values */ private void updateTypeInformation(AtomicValue key, Sequence<?> val, boolean wasEmpty) { // if (Instrumentation.ACTIVE) { // Instrumentation.count("updateTypeInformation"); // } if (wasEmpty) { keyUType = key.getUType(); valueUType = SequenceTool.getUType(val); keyAtomicType = key.getItemType(); valueItemType = MapItem.getItemTypeOfSequence(val); valueCardinality = SequenceTool.getCardinality(val); } else { keyUType = keyUType.union(key.getUType()); valueUType = valueUType.union(SequenceTool.getUType(val)); valueCardinality = Cardinality.union(valueCardinality, SequenceTool.getCardinality(val)); if (key.getItemType() != keyAtomicType) { keyAtomicType = null; } if (!MapItem.isKnownToConform(val, valueItemType)) { valueItemType = null; } } }
} else { throw new XPathException("Cannot convert value " + value.getClass() + " of type " + SequenceTool.getItemType(value, context.getConfiguration().getTypeHierarchy()) + " to class " + targetClass.getName());
/** * Factory method to construct a CardinalityChecker. The method may create an expression that combines * the cardinality checking with the functionality of the underlying expression class * * @param sequence the base sequence whose cardinality is to be checked * @param cardinality the required cardinality * @param role information to be used in error reporting * @return a new Expression that does the CardinalityChecking (not necessarily a CardinalityChecker) */ public static Expression makeCardinalityChecker(Expression sequence, int cardinality, RoleDiagnostic role) { Expression result; if (sequence instanceof Literal && Cardinality.subsumes(cardinality, SequenceTool.getCardinality(((Literal) sequence).getValue()))) { return sequence; } if (sequence instanceof Atomizer && !Cardinality.allowsMany(cardinality)) { Expression base = ((Atomizer) sequence).getBaseExpression(); result = new SingletonAtomizer(base, role, Cardinality.allowsZero(cardinality)); } else { result = new CardinalityChecker(sequence, cardinality, role); } ExpressionTool.copyLocationInfo(sequence, result); return result; }
/** * Determine whether two sequences have the same number of items. This is more efficient * than comparing the counts, because the longer sequence is evaluated only as far as the * length of the shorter sequence. The method consumes the supplied iterators. * * @param a iterator over the first sequence * @param b iterator over the second sequece * @return true if the lengths of the two sequences are the same */ public static boolean sameLength(SequenceIterator a, SequenceIterator b) throws XPathException { if ((a.getProperties() & SequenceIterator.LAST_POSITION_FINDER) != 0) { return hasLength(b, ((LastPositionFinder) a).getLength()); } else if ((b.getProperties() & SequenceIterator.LAST_POSITION_FINDER) != 0) { return hasLength(a, ((LastPositionFinder) b).getLength()); } else { while (true) { Item itA = a.next(); Item itB = b.next(); if (itA == null || itB == null) { if (itA != null) { a.close(); } if (itB != null) { b.close(); } return itA == null && itB == null; } } } }
@Override public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException { //return Int64Value.makeIntegerValue(SequenceTool.convertToJava(arguments[0].head()).hashCode()); return new Int64Value(SequenceTool.convertToJava(arguments[0].head()).hashCode()); } };