Example usage for jdk.nashorn.internal.objects NativeNumber constructor

List of usage examples for jdk.nashorn.internal.objects NativeNumber constructor

Introduction

In this page you can find the example usage for jdk.nashorn.internal.objects NativeNumber constructor.

Prototype

@Constructor(arity = 1)
public static Object constructor(final boolean newObj, final Object self, final Object... args) 

Source Link

Document

ECMA 15.7.2 - The Number constructor

Usage

From source file:com.mongodb.jvm.json.nashorn.NativeNumberTransformer.java

License:Apache License

public Object transform(Object object, JsonImplementation implementation) {
    if (object instanceof ScriptObject) {
        Object numberLong = ((ScriptObject) object).get("$numberLong");
        if ((numberLong != null) && (numberLong.getClass() != Undefined.class)) {
            // Might throw a NumberFormatException
            Long asLong = Long.parseLong(numberLong.toString());
            Double asDouble = asLong.doubleValue();

            if (JsonUtil.numberToString(asLong).equals(JsonUtil.numberToString(asDouble)))
                // Converting to double doesn't lose accuracy
                return NativeNumber.constructor(true, null, asDouble);
        }/*www .j a va 2s. c om*/
    }

    return null;
}

From source file:com.threecrickets.jvm.json.nashorn.NashornJsonImplementation.java

License:Mozilla Public License

public Object createDouble(double value) {
    return NativeNumber.constructor(true, null, value);
}

From source file:com.threecrickets.jvm.json.nashorn.util.NashornNativeUtil.java

License:Mozilla Public License

public static NativeNumber toNumber(Object value) {
    return (NativeNumber) NativeNumber.constructor(true, null, value);
}

From source file:org.bson.jvm.nashorn.NativeNumberCodec.java

License:Apache License

public NativeNumber decode(BsonReader reader, DecoderContext decoderContext) {
    return (NativeNumber) NativeNumber.constructor(true, null, reader.readDouble());
}