Example usage for java.lang Number longValue

List of usage examples for java.lang Number longValue

Introduction

In this page you can find the example usage for java.lang Number longValue.

Prototype

public abstract long longValue();

Source Link

Document

Returns the value of the specified number as a long .

Usage

From source file:org.eclipse.wb.internal.core.eval.evaluators.LongEvaluator.java

/**
 * Converts given {@link Expression} into "long" value.
 *///from   ww  w .j a va 2  s.c  o  m
private static long getLongValue(EvaluationContext context, Expression expression) throws Exception {
    Object value = AstEvaluationEngine.evaluate(context, expression);
    // Character
    if (value instanceof Character) {
        Character character = (Character) value;
        return character.charValue();
    }
    // Number
    Number number = (Number) value;
    return number.longValue();
}

From source file:Main.java

public static ArrayList<Long> JSONArrayToArrayListLong(JSONArray input) throws JSONException {
    ArrayList<Long> output = new ArrayList<Long>();
    Number entry;

    if (input == null)
        return null;

    for (int i = 0; i < input.length(); i++) {
        entry = (Number) input.get(i);
        output.add(entry.longValue());
    }/*from w  w  w  . j  a v  a  2s.co m*/

    return output;
}

From source file:org.openconcerto.erp.panel.compta.ExportEBP_ComptaPro.java

static private String formatCents(final Number n) {
    return DECIMAL_FORMAT.format(BigDecimal.valueOf(n.longValue()).movePointLeft(2));
}

From source file:com.sunchenbin.store.feilong.core.util.RandomUtil.java

/**
 * ??./*from  w ww.  j  a  v a 2  s .c  o m*/
 *
 * @param min
 *            ?
 * @param max
 *            
 * @return ??
 */
public static long createRandom(Number min, Number max) {
    long maxLong = max.longValue();
    long minLong = min.longValue();
    if (maxLong < minLong) {
        String messagePattern = "maxLong:[{}] can not < minLong:[{}]";
        throw new IllegalArgumentException(Slf4jUtil.formatMessage(messagePattern, maxLong, minLong));
    }
    long cha = maxLong - minLong;
    return minLong + createRandom(cha);
}

From source file:Main.java

/**
 * @param value A number/*from  ww w.j a  v  a  2  s  .c  o m*/
 *
 * @return The number as a {@link BigInteger}.
 */
public static BigInteger asBigInteger(Number number) {
    if (number == null) {
        return null;
    }

    if (number instanceof BigInteger) {
        return (BigInteger) number;
    }

    return BigInteger.valueOf(number.longValue());
}

From source file:io.appform.jsonrules.utils.ComparisonUtils.java

static int compare(JsonNode evaluatedNode, Object value) {
    int comparisonResult = 0;
    if (evaluatedNode.isNumber()) {
        if (Number.class.isAssignableFrom(value.getClass())) {
            Number nValue = (Number) value;
            if (evaluatedNode.isIntegralNumber()) {
                comparisonResult = Long.compare(evaluatedNode.asLong(), nValue.longValue());
            } else if (evaluatedNode.isFloatingPointNumber()) {
                comparisonResult = Double.compare(evaluatedNode.asDouble(), nValue.doubleValue());
            }/*from   w w w.  j  av  a 2s .  c  o  m*/
        } else {
            throw new IllegalArgumentException("Type mismatch between operator and operand");
        }
    } else if (evaluatedNode.isBoolean()) {
        if (Boolean.class.isAssignableFrom(value.getClass())) {
            Boolean bValue = Boolean.parseBoolean(value.toString());
            comparisonResult = Boolean.compare(evaluatedNode.asBoolean(), bValue);
        } else {
            throw new IllegalArgumentException("Type mismatch between operator and operand");
        }

    } else if (evaluatedNode.isTextual()) {
        if (String.class.isAssignableFrom(value.getClass())) {
            comparisonResult = evaluatedNode.asText().compareTo(String.valueOf(value));
        } else {
            throw new IllegalArgumentException("Type mismatch between operator and operand");
        }
    } else if (evaluatedNode.isObject()) {
        throw new IllegalArgumentException("Object comparisons not supported");
    }
    return comparisonResult;
}

From source file:mil.jpeojtrs.sca.util.PrimitiveArrayUtils.java

public static long[] convertToLongArray(final Object array) {
    if (array == null) {
        return null;
    }/*from  www  .j a  v  a  2 s .  c  o m*/
    if (array instanceof long[]) {
        return (long[]) array;
    }
    if (array instanceof Long[]) {
        return ArrayUtils.toPrimitive((Long[]) array);
    }
    final long[] newArray = new long[Array.getLength(array)];
    for (int i = 0; i < newArray.length; i++) {
        final Number val = (Number) Array.get(array, i);
        newArray[i] = val.longValue();
    }
    return newArray;
}

From source file:com.feilong.commons.core.util.RandomUtil.java

/**
 * ??.//from   ww w.ja va  2  s  .co m
 * 
 * @param min
 *            ?
 * @param max
 *            
 * @return ??
 * @throws IllegalArgumentException
 *             {@code if (maxLong < minLong)}
 */
public static long createRandom(Number min, Number max) throws IllegalArgumentException {
    long maxLong = max.longValue();
    long minLong = min.longValue();
    if (maxLong < minLong) {
        String messagePattern = "maxLong:[{}] can not < minLong:[{}]";
        throw new IllegalArgumentException(Slf4jUtil.formatMessage(messagePattern, maxLong, minLong));
    }
    long cha = maxLong - minLong;
    return minLong + createRandom(cha);
}

From source file:net.dontdrinkandroot.utils.lang.math.NumberUtils.java

/**
 * Get the null safe longValue of a Number. Defaults to 0.
 * /*from w ww . j  a  v a 2s.co  m*/
 * @param number
 *            The Number to convert.
 * @return The null safe longValue. Defaults to 0.
 */
public static long longValue(final Number number) {

    if (number == null) {
        return 0;
    }

    return number.longValue();
}

From source file:es.bsc.amon.util.tree.TreeNodeFactory.java

public static JsonNode toJson(TreeNode n) {
    JsonNode json = null;//  w ww. j a v  a2s .com
    if (n instanceof ObjNode) {
        json = new ObjectNode(JsonNodeFactory.instance);
        for (Map.Entry<String, TreeNode> e : ((ObjNode) n).properties.entrySet()) {
            ((ObjectNode) json).put(e.getKey(), toJson(e.getValue()));
        }
    } else if (n instanceof NodeArray) {
        json = new ArrayNode(JsonNodeFactory.instance);
        for (TreeNode ne : ((NodeArray) n).elements) {
            ((ArrayNode) json).add(toJson(ne));
        }
    } else if (n instanceof StringValue) {
        json = new TextNode(((StringValue) n).value);
    } else if (n instanceof NumberValue) {
        Number val = ((NumberValue) n).value;
        if (val instanceof Byte || val instanceof Short || val instanceof Integer || val instanceof Long) {
            json = new LongNode(val.longValue());
        } else {
            json = new DoubleNode(val.doubleValue());
        }
    } else
        throw new RuntimeException("You should not reach this");
    return json;
}