Package net.sf.saxon.value

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.getPrimitiveValue();
        int pos = (int)n.longValue();
        SequenceIterator ins = argument[2].iterate(context);
        return new InsertIterator(seq, ins, pos);
    }
View Full Code Here


        Controller ctrl = context.getController();
        DecimalFormatManager dfm = ctrl.getDecimalFormatManager();
        DecimalFormatSymbols dfs;

        AtomicValue av0 = (AtomicValue)argument[0].evaluateItem(context);
        NumericValue number = (NumericValue)av0.getPrimitiveValue();
        String format = argument[1].evaluateItem(context).getStringValue();

        if (numArgs==2) {
            dfs = dfm.getDefaultDecimalFormat();
        } else {
            String uri = dfURI;
            String localName = dfLocalName;
            if (localName==null) {
                // the decimal-format name was given as a run-time expression
                String qname = argument[2].evaluateItem(context).getStringValue();
                if (!Name.isQName(qname)) {
                    DynamicError e = new DynamicError("Decimal format name '" + qname + "' is not a valid QName");
                    e.setXPathContext(context);
                    e.setErrorCode("XT1280");
                    throw e;
                }
                try {
                    String[] parts = Name.getQNameParts(qname);
                    localName = parts[1];
                    uri = nsContext.getURIForPrefix(parts[0], false);
                    if (uri==null) {
                        DynamicError e = new DynamicError("Namespace prefix '" + parts[0] + "' has not been defined");
                        e.setXPathContext(context);
                        e.setErrorCode("XT1280");
                        throw e;
                    }
                } catch (QNameException e) {
                    dynamicError("Invalid decimal format name. " + e.getMessage(), "XT1280", context);
                }
            }
            dfs = dfm.getNamedDecimalFormat(uri, localName);
            if (dfs==null) {
                DynamicError e = new DynamicError(
                    "format-number function: decimal-format '" + localName + "' is not defined");
                e.setXPathContext(context);
                e.setErrorCode("XT1280");
                throw e;
            }
        }
        return formatNumber(number.getDoubleValue(), format, dfs, context);
    }
View Full Code Here

        Controller ctrl = context.getController();

        DecimalFormatSymbols dfs = decimalFormatSymbols;

        AtomicValue av0 = (AtomicValue)argument[0].evaluateItem(context);
        NumericValue number = (NumericValue)av0.getPrimitiveValue();

        if (dfs == null) {
            // the decimal-format name was not resolved statically
            if (requireFixup) {
                // we registered for a fixup, but none came
                dynamicError("Unknown decimal format name", "XT1280", context);
                return null;
            }
            DecimalFormatManager dfm = ctrl.getDecimalFormatManager();
            if (numArgs==2) {
                dfs = dfm.getDefaultDecimalFormat();
            } else {
                // the decimal-format name was given as a run-time expression
                String qname = argument[2].evaluateItem(context).getStringValue();
                try {
                    String[] parts = Name.getQNameParts(qname);
                    String localName = parts[1];
                    String uri = nsContext.getURIForPrefix(parts[0], false);
                    if (uri==null) {
                        dynamicError("Namespace prefix '" + parts[0] + "' has not been defined", "XT1280", context);
                        return null;
                    }
                    dfs = dfm.getNamedDecimalFormat(uri, localName);
                    if (dfs==null) {
                        dynamicError(
                            "format-number function: decimal-format '" + localName + "' is not defined", "XT1280", context);
                        return null;
                    }
                } catch (QNameException e) {
                    dynamicError("Invalid decimal format name. " + e.getMessage(), "XT1280", context);
                }
            }
        }
        SubPicture[] pics = subPictures;
        if (pics == null) {
            String format = argument[1].evaluateItem(context).getStringValue();
            pics = getSubPictures(format, dfs);
        }
        return formatNumber(number.getDoubleValue(), pics, dfs).toString();
    }
View Full Code Here

                AtomicValue val = (AtomicValue) iter.next();
                if (val == null) {
                    break;
                }
                try {
                    NumericValue num;
                    if (val instanceof NumericValue) {
                        num = (NumericValue) val;
                    } else {
                        num = NumberFn.convert(val);
                    }
                    num = num.round();
                    if (num.compareTo(IntegerValue.MAX_LONG) > 0) {
                        DynamicError e = new DynamicError("A number is too large to be formatted");
                        e.setXPathContext(context);
                        e.setErrorCode("SAXON:0000");
                        throw e;
                    }
                    if (num.compareTo(IntegerValue.MIN_LONG) < 0) {
                        DynamicError e = new DynamicError("The numbers to be formatted must be positive");
                        e.setXPathContext(context);
                        e.setErrorCode("XT0980");
                        throw e;
                    }
                    long i = ((NumericValue) num.convert(Type.INTEGER, context)).longValue();
                    if (i < 1) {
                        DynamicError e = new DynamicError("The numbers to be formatted must be positive");
                        e.setXPathContext(context);
                        e.setErrorCode("XT0980");
                        throw e;
View Full Code Here

    public SequenceIterator iterate(XPathContext context) throws XPathException {
        AtomicValue av1 = (AtomicValue)operand0.evaluateItem(context);
        if (av1 == null) {
            return new EmptyIterator();
        }
        NumericValue v1 = (NumericValue)av1.getPrimitiveValue();

        AtomicValue av2 = (AtomicValue)operand1.evaluateItem(context);
        if (av2 == null) {
            return new EmptyIterator();
        }
        NumericValue v2 = (NumericValue)av2.getPrimitiveValue();

        if (v1.compareTo(v2) > 0) {
            return new EmptyIterator();
        }
        return new RangeIterator(v1.longValue(), v2.longValue());
    }
View Full Code Here

    */

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

    */

    private static NumericValue[] getRange(SequenceIterator iter) throws XPathException {
        NumericValue[] range = null;
        while (true) {
            NumericValue val = (NumericValue)iter.next();
            if (val == null) break;

            if (val.isNaN()) continue;

            if (range == null) {
                range = new NumericValue[2];
                range[0] = val;
                range[1] = val;
            } else {
                if (val.compareTo(range[0]) < 0) {
                    range[0] = val;
                }
                if (val.compareTo(range[1]) > 0) {
                    range[1] = val;
                }
            }
        }
        return range;
View Full Code Here

    */

    private static CharSequence unicodeToString(SequenceIterator chars, XPathContext context) throws XPathException {
        StringBuffer sb = new StringBuffer();
        while (true) {
            NumericValue nextInt = (NumericValue)chars.next();
            if (nextInt == null) {
                return sb;
            }
            long next = nextInt.longValue();
            if (next > Integer.MAX_VALUE || !XMLChar.isValid((int)next)) {
                DynamicError e = new DynamicError("Invalid XML character [decimal " + next + "]");
                e.setXPathContext(context);
                throw e;
            }
View Full Code Here

    */

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

        if (argument.length==3) {
            AtomicValue lengthVal0 = (AtomicValue)argument[2].evaluateItem(context);
            NumericValue lengthVal = (NumericValue)lengthVal0.getPrimitiveValue();
            int end = start + (int)lengthVal.round().longValue() - 1;
            if (start < 1) {
                start = 1;
            }
            return PositionIterator.make(seq, start, end);
        } else {
View Full Code Here

    public Item evaluateItem(XPathContext c) throws XPathException {
        AtomicValue av = (AtomicValue)value.evaluateItem(c);
        if (av==null) {
            return BooleanValue.FALSE;
        }
        NumericValue v = (NumericValue)av.getPrimitiveValue();

        AtomicValue av2 = (AtomicValue)min.evaluateItem(c);
        NumericValue v2 = (NumericValue)av2.getPrimitiveValue();

        if (v.compareTo(v2) < 0) {
            return BooleanValue.FALSE;
        }
        AtomicValue av3 = (AtomicValue)max.evaluateItem(c);
        NumericValue v3 = (NumericValue)av3.getPrimitiveValue();

        return BooleanValue.get(v.compareTo(v3) <= 0);
    }
View Full Code Here

TOP

Related Classes of net.sf.saxon.value.NumericValue

Copyright © 2018 www.massapicom. 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.