/** * Copy an expression. This makes a deep copy. * * @return the copy of the original expression */ public Expression copy() { return new FirstItemExpression(getBaseExpression().copy()); }
/** * Constructor * @param base A sequence expression denoting sequence whose first item is to be returned */ public FirstItemExpression(Expression base) { super(base); computeStaticProperties(); }
/** * Promote this expression if possible */ public Expression promote(PromotionOffer offer) throws XPathException { Expression exp = offer.accept(this); if (exp != null) { return exp; } else { if (offer.action != PromotionOffer.UNORDERED) { // we can't push the UNORDERED property down to the operand, because order is significant operand = doPromotion(operand, offer); } return this; } }
/** * Static factory method * * @param base A sequence expression denoting sequence whose first item is to be returned * @return the FirstItemExpression, or an equivalent */ public static Expression makeFirstItemExpression(Expression base) { if (base instanceof FirstItemExpression) { return base; } else { return new FirstItemExpression(base); } }
@Override public String toShortString() { return getBaseExpression().toShortString() + "[1]"; }
@Override public Expression makeFunctionCall(Expression[] arguments) { return FirstItemExpression.makeFirstItemExpression(arguments[0]); }
/** * Static factory method * * @param base A sequence expression denoting sequence whose first item is to be returned * @return the FirstItemExpression, or an equivalent */ public static Expression makeFirstItemExpression(Expression base) { if (base instanceof FirstItemExpression) { return base; } else { return new FirstItemExpression(base); } }
@Override public String toShortString() { return getBaseExpression().toShortString() + "[1]"; }
@Override public Expression makeFunctionCall(Expression[] arguments) { return FirstItemExpression.makeFirstItemExpression(arguments[0]); }
/** * Make an expression that extracts the first item of a sequence, after atomization */ public static Expression makeFirstItem(Expression exp, StaticContext env) { final TypeHierarchy th = env.getConfiguration().getTypeHierarchy(); if (!exp.getItemType(th).isAtomicType()) { exp = new Atomizer(exp, env.getConfiguration()); } if (Cardinality.allowsMany(exp.getCardinality())) { exp = new FirstItemExpression(exp); } if (!th.isSubType(exp.getItemType(th), BuiltInAtomicType.STRING)) { exp = new AtomicSequenceConverter(exp, BuiltInAtomicType.STRING); } return exp; }
/** * Copy an expression. This makes a deep copy. * * @return the copy of the original expression */ public Expression copy() { return new FirstItemExpression(getBaseExpression().copy()); }
public AbstractExpression exprFor (FirstItemExpression expr) { return new Subsequence (exprFor (expr.getBaseExpression()), LiteralExpression.ONE, LiteralExpression.ONE); }
public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException { getOperand().optimize(visitor, contextInfo); if (Literal.isConstantOne(getSubscript())) { return FirstItemExpression.makeFirstItemExpression(getBaseExpression()); } return this; }
/** * Constructor * @param base A sequence expression denoting sequence whose first item is to be returned */ public FirstItemExpression(Expression base) { super(base); computeStaticProperties(); }
/** * Promote this expression if possible */ public Expression promote(PromotionOffer offer) throws XPathException { Expression exp = offer.accept(this); if (exp != null) { return exp; } else { if (offer.action != PromotionOffer.UNORDERED) { // we can't push the UNORDERED property down to the operand, because order is significant operand = doPromotion(operand, offer); } return this; } }
/** * Make an expression that extracts the first item of a sequence, after atomization */ public static Expression makeFirstItem(Expression exp, StaticContext env) { final TypeHierarchy th = env.getConfiguration().getTypeHierarchy(); if (!exp.getItemType(th).isAtomicType()) { exp = new Atomizer(exp, env.getConfiguration()); } if (Cardinality.allowsMany(exp.getCardinality())) { exp = new FirstItemExpression(exp); } if (!th.isSubType(exp.getItemType(th), BuiltInAtomicType.STRING)) { exp = new AtomicSequenceConverter(exp, BuiltInAtomicType.STRING); } return exp; }
/** * Copy an expression. This makes a deep copy. * * @return the copy of the original expression */ public Expression copy() { return new FirstItemExpression(getBaseExpression().copy()); }
/** * Evaluate the expression */ public Item evaluateItem(XPathContext context) throws XPathException { SequenceIterator iter = getBaseExpression().iterate(context); Item result = iter.next(); iter.close(); return result; }
public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException { getOperand().optimize(visitor, contextInfo); if (Literal.isConstantOne(getSubscript())) { return FirstItemExpression.makeFirstItemExpression(getBaseExpression()); } return this; }
/** * Constructor * @param base A sequence expression denoting sequence whose first item is to be returned */ public FirstItemExpression(Expression base) { super(base); computeStaticProperties(); }