Examples of NumericValue


Examples of net.sf.saxon.value.NumericValue

    */

    public SequenceIterator iterate(XPathContext context) throws XPathException {
        SequenceIterator seq = argument[0].iterate(context);
        AtomicValue n0 = (AtomicValue)argument[1].evaluateItem(context);
        NumericValue n = (NumericValue)n0;
        int pos = (int)n.longValue();
        if (pos < 1) {
            return seq;
        }
        return new RemoveIterator(seq, pos);
    }
View Full Code Here

Examples of net.sf.saxon.value.NumericValue

        Expression e = super.optimize(visitor, contextItemType);
        if (e != this) {
            return e;
        }
        if (getNumberOfArguments() == 2 && Literal.isAtomic(argument[1])) {
            NumericValue start = (NumericValue)((Literal)argument[1]).getValue();
            start = start.round();
            long intstart = start.longValue();
            if (intstart > Integer.MAX_VALUE) {
                return new Literal(EmptySequence.getInstance());
            }
            return new TailExpression(argument[0], (int)intstart);
        }
View Full Code Here

Examples of net.sf.saxon.value.NumericValue

    */

    public SequenceIterator iterate(XPathContext context) throws XPathException {
        SequenceIterator seq = argument[0].iterate(context);
        AtomicValue startVal0 = (AtomicValue)argument[1].evaluateItem(context);
        NumericValue startVal = (NumericValue)startVal0;

        if (argument.length == 2) {
            long lstart;
            if (startVal instanceof Int64Value) {
                lstart = startVal.longValue();
                if (lstart <= 1) {
                    return seq;
                }
            } else {
                startVal = startVal.round();
                if (startVal.compareTo(Int64Value.PLUS_ONE) <= 0) {
                    return seq;
                } else if (startVal.compareTo(Int64Value.MAX_LONG) > 0) {
                    return EmptyIterator.getInstance();
                } else if (startVal.isNaN()) {
                    return EmptyIterator.getInstance();
                } else {
                    lstart = startVal.longValue();
                }
            }

            if (lstart > Integer.MAX_VALUE) {
                // we don't allow sequences longer than an this
                return EmptyIterator.getInstance();
            }

            return TailIterator.make(seq, (int)lstart);

        } else {

            // There are three arguments

            AtomicValue lengthVal0 = (AtomicValue)argument[2].evaluateItem(context);
            NumericValue lengthVal = (NumericValue)lengthVal0;

            if (startVal instanceof Int64Value && lengthVal instanceof Int64Value) {
                long lstart = startVal.longValue();
                if (lstart > Integer.MAX_VALUE) {
                    return EmptyIterator.getInstance();
                }
                long llength = lengthVal.longValue();
                if (llength > Integer.MAX_VALUE) {
                    llength = Integer.MAX_VALUE;
                }
                if (llength < 1) {
                    return EmptyIterator.getInstance();
                }
                long lend = lstart + llength - 1;
                if (lend < 1) {
                    return EmptyIterator.getInstance();
                }
                int start = (lstart < 1 ? 1 : (int)lstart);
                return SubsequenceIterator.make(seq, start, (int)lend);
            } else {
                if (startVal.isNaN()) {
                    return EmptyIterator.getInstance();
                }
                if (startVal.compareTo(Int64Value.MAX_LONG) > 0) {
                    return EmptyIterator.getInstance();
                }
                startVal = startVal.round();

                if (lengthVal.isNaN()) {
                    return EmptyIterator.getInstance();
                }
                lengthVal = lengthVal.round();

                if (lengthVal.compareTo(Int64Value.ZERO) <= 0) {
                    return EmptyIterator.getInstance();
                }
                NumericValue rend = (NumericValue)ArithmeticExpression.compute(
                        startVal, Calculator.PLUS, lengthVal, context);
                rend = (NumericValue)ArithmeticExpression.compute(
                        rend, Calculator.MINUS, Int64Value.PLUS_ONE, context);
                if (rend.compareTo(Int64Value.ZERO) <= 0) {
                    return EmptyIterator.getInstance();
                }

                long lstart;
                if (startVal.compareTo(Int64Value.PLUS_ONE) <= 0) {
                    lstart = 1;
                } else {
                    lstart = startVal.longValue();
                }
                if (lstart > Integer.MAX_VALUE) {
                    return EmptyIterator.getInstance();
                }

                long lend;
                if (rend.compareTo(Int64Value.MAX_LONG) >= 0) {
                    lend = Integer.MAX_VALUE;
                } else {
                    lend = rend.longValue();
                }
                return SubsequenceIterator.make(seq, (int)lstart, (int)lend);

            }
        }
View Full Code Here

Examples of net.sf.saxon.value.NumericValue

         *          consistent with each other).
         */

        public Expression rewrite(StaticContext context, Expression[] arguments) throws XPathException {
            if (arguments[1] instanceof Literal) {
                NumericValue val = (NumericValue)((Literal)arguments[1]).getValue();
                if (val.compareTo(1) < 0 || val.compareTo(Integer.MAX_VALUE) > 0 || !val.isWholeNumber()) {
                    return new Literal(EmptySequence.getInstance());
                }
                if (val.compareTo(1) > 0 && !Cardinality.allowsMany(arguments[0].getCardinality())) {
                    return new Literal(EmptySequence.getInstance());
                }
            }
            return null;
        }
View Full Code Here

Examples of net.sf.saxon.value.NumericValue

         *          if a dynamic error occurs during evaluation of the function. The Saxon run-time
         *          code will add information about the error location.
         */

        public SequenceIterator call(SequenceIterator[] arguments, XPathContext context) throws XPathException {
            NumericValue index = (NumericValue)arguments[1].next();
            if (index == null) {
                return EmptyIterator.getInstance();
            }
            if (index.compareTo(Integer.MAX_VALUE) <= 0 && index.isWholeNumber()) {
                int intindex = (int)index.longValue();
                if (intindex < 1) {
                    return EmptyIterator.getInstance();
                }
                Item item;
                SequenceIterator base = arguments[0];
View Full Code Here

Examples of net.sf.saxon.value.NumericValue

            sv = StringValue.EMPTY_STRING;
        }
        String s = sv.getStringValue();

        AtomicValue a1 = (AtomicValue)argument[1].evaluateItem(context);
        NumericValue a = (NumericValue)a1.getPrimitiveValue();

        if (argument.length==2) {
            return new StringValue(substring(s, a));
        } else {
            AtomicValue b2 = (AtomicValue)argument[2].evaluateItem(context);
            NumericValue b = (NumericValue)b2.getPrimitiveValue();
            return new StringValue(substring(s, a, b, context));
        }
    }
View Full Code Here

Examples of net.sf.saxon.value.NumericValue

        long lstart;
        if (start instanceof IntegerValue) {
            lstart = ((IntegerValue)start).longValue();
        } else {
            NumericValue rstart = start.round();
            // We need to be careful to handle cases such as plus/minus infinity
            if (rstart.compareTo(IntegerValue.ZERO) <= 0) {
                return s;
            } else if (rstart.compareTo(new IntegerValue(slength)) > 0) {
                // this works even where the string contains surrogate pairs,
                // because the Java length is always >= the XPath length
                return "";
            } else {
                try {
                    lstart = rstart.longValue();
                } catch (XPathException err) {
                    // this shouldn't happen unless the string length exceeds the bounds
                    // of a long
                    throw new AssertionError("string length out of permissible range");
                }
View Full Code Here

Examples of net.sf.saxon.value.NumericValue

                    throw new AssertionError("string length out of permissible range");
                }
            }
        }

        NumericValue end;
        try {
            end = start.arithmetic(Token.PLUS, len.round(), context);
        } catch (XPathException e) {
            throw new AssertionError("Unexpected arithmetic failure in substring");
        }
        long lend;
        if (end instanceof IntegerValue) {
            lend = ((IntegerValue)end).longValue();
        } else {
            // We need to be careful to handle cases such as plus/minus infinity and NaN
            if (end.compareTo(IntegerValue.ZERO) <= 0) {
                return "";
            } else if (end.isNaN()) {
                return "";
            } else if (end.compareTo(new IntegerValue(slength)) > 0) {
                // this works even where the string contains surrogate pairs,
                // because the Java length is always >= the XPath length
                lend = slength+1;
            } else {
                try {
                    lend = end.ceiling().longValue();
                } catch (XPathException err) {
                    // this shouldn't happen unless the string length exceeds the bounds
                    // of a long
                    throw new AssertionError("string length out of permissible range");
                }
View Full Code Here

Examples of net.sf.saxon.value.NumericValue

    * Evaluate in a general context
    */

    public Item evaluateItem(XPathContext c) throws XPathException {
        AtomicValue gp0 = (AtomicValue)argument[0].evaluateItem(c);
        NumericValue gp = (NumericValue)gp0.getPrimitiveValue();
        RegexIterator iter = c.getCurrentRegexIterator();
        if (iter == null) return null;
        String s = iter.getRegexGroup((int)gp.longValue());
        if (s == null) return null;
        return new StringValue(s);
    }
View Full Code Here

Examples of net.sf.saxon.value.NumericValue

    public Item evaluateItem(XPathContext context) throws XPathException {

        AtomicValue val0 = (AtomicValue)argument[0].evaluateItem(context);
        if (val0==null) return null;
        NumericValue val = (NumericValue)val0.getPrimitiveValue();

        switch (operation) {
            case FLOOR:
                return val.floor();
            case CEILING:
                return val.ceiling();
            case ROUND:
                return val.round();
            case HALF_EVEN:
                int scale = 0;
                if (argument.length==2) {
                    AtomicValue scaleVal0 = (AtomicValue)argument[1].evaluateItem(context);
                    NumericValue scaleVal = (NumericValue)scaleVal0.getPrimitiveValue();
                    scale = (int)scaleVal.longValue();
                }
                return val.roundToHalfEven(scale);
            case ABS:
                int sign = val.compareTo(IntegerValue.ZERO);
                if (sign < 0) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.