当前位置: 首页>>代码示例>>Java>>正文


Java JSType.isRepresentableAsLong方法代码示例

本文整理汇总了Java中jdk.nashorn.internal.runtime.JSType.isRepresentableAsLong方法的典型用法代码示例。如果您正苦于以下问题:Java JSType.isRepresentableAsLong方法的具体用法?Java JSType.isRepresentableAsLong怎么用?Java JSType.isRepresentableAsLong使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jdk.nashorn.internal.runtime.JSType的用法示例。


在下文中一共展示了JSType.isRepresentableAsLong方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: validLength

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
static long validLength(final Object length, final boolean reject) {
    final double doubleLength = JSType.toNumber(length);
    if (!Double.isNaN(doubleLength) && JSType.isRepresentableAsLong(doubleLength)) {
        final long len = (long) doubleLength;
        if (len >= 0 && len <= JSType.MAX_UINT) {
            return len;
        }
    }
    if (reject) {
        throw rangeError("inappropriate.array.length", ScriptRuntime.safeToString(length));
    }
    return -1;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:14,代码来源:NativeArray.java

示例2: set

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
@Override
public ArrayData set(final int index, final double value, final boolean strict) {
    if (JSType.isRepresentableAsLong(value)) {
        array[index] = (long)value;
        setLength(Math.max(index + 1, length()));
        return this;
    }
    return convert(Double.class).set(index, value, strict);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:LongArrayData.java

示例3: getValueOf

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
 * Return value of token given its token descriptor.
 *
 * @param token  Token descriptor.
 * @return JavaScript value.
 */
Object getValueOf(final long token, final boolean strict) {
    final int start = Token.descPosition(token);
    final int len   = Token.descLength(token);

    switch (Token.descType(token)) {
    case DECIMAL:
        return Lexer.valueOf(source.getString(start, len), 10); // number
    case OCTAL:
        return Lexer.valueOf(source.getString(start, len), 8); // number
    case HEXADECIMAL:
        return Lexer.valueOf(source.getString(start + 2, len - 2), 16); // number
    case FLOATING:
        final String str   = source.getString(start, len);
        final double value = Double.valueOf(str);
        if (str.indexOf('.') != -1) {
            return value; //number
        }
        //anything without an explicit decimal point is still subject to a
        //"representable as int or long" check. Then the programmer does not
        //explicitly code something as a double. For example new Color(int, int, int)
        //and new Color(float, float, float) will get ambiguous for cases like
        //new Color(1.0, 1.5, 1.5) if we don't respect the decimal point.
        //yet we don't want e.g. 1e6 to be a double unnecessarily
        if (JSType.isRepresentableAsInt(value) && !JSType.isNegativeZero(value)) {
            return (int)value;
        } else if (JSType.isRepresentableAsLong(value) && !JSType.isNegativeZero(value)) {
            return (long)value;
        }
        return value;
    case STRING:
        return source.getString(start, len); // String
    case ESCSTRING:
        return valueOfString(start, len, strict); // String
    case IDENT:
        return valueOfIdent(start, len); // String
    case REGEX:
        return valueOfPattern(start, len); // RegexToken::LexerToken
    case XML:
        return valueOfXML(start, len); // XMLToken::LexerToken
    case DIRECTIVE_COMMENT:
        return source.getString(start, len);
    default:
        break;
    }

    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:54,代码来源:Lexer.java

示例4: getArrayIndex

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
 * Return a valid index for this double, if it represents one.
 *
 * Doubles that aren't representable exactly as longs/ints aren't working
 * array indexes, however, array[1.1] === array["1.1"] in JavaScript.
 *
 * @param key the key to check
 * @return the array index this double represents or {@code -1} if this isn't a valid index.
 *         Note that negative return values other than {@code -1} are considered valid and can be converted to
 *         the actual index using {@link #toLongIndex(int)}.
 */
public static int getArrayIndex(final double key) {
    if (JSType.isRepresentableAsInt(key)) {
        return getArrayIndex((int) key);
    } else if (JSType.isRepresentableAsLong(key)) {
        return getArrayIndex((long) key);
    }

    return INVALID_ARRAY_INDEX;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:ArrayIndex.java


注:本文中的jdk.nashorn.internal.runtime.JSType.isRepresentableAsLong方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。