List of usage examples for java.lang Number longValue
public abstract long longValue();
From source file:name.martingeisse.phunky.runtime.variable.TypeConversionUtil.java
/** * Converts the specified value to an integer value. * @param value the original value// w w w. j a v a2s .c o m * @return the converted value */ public static long convertToInteger(Object value) { if (value == null) { return 0; } if (value instanceof Number) { Number v = (Number) value; return v.longValue(); } if (value instanceof String) { String v = (String) value; if (v.isEmpty()) { return 0; } // TODO parse int *prefix* of the string try { return Long.parseLong(v); } catch (NumberFormatException e) { return 1; } } if (value instanceof Boolean) { Boolean v = (Boolean) value; return (v ? 1 : 0); } if (value instanceof PhpValueArray) { PhpValueArray v = (PhpValueArray) value; return (v.isEmpty() ? 0 : 1); } return 1; }
From source file:org.openestate.io.idx.IdxFormat.java
public static Long parseLong(String value) throws NumberFormatException { Number number = parseNumber(value, false); return (number != null) ? number.longValue() : null; }
From source file:org.apache.accumulo.examples.wikisearch.function.QueryFunctions.java
public static Number abs(String fieldValue) { Number retval = null;/*ww w . j a v a 2 s .c o m*/ try { Number value = NumberUtils.createNumber(fieldValue); if (null == value) retval = (Number) Integer.MIN_VALUE; else if (value instanceof Long) retval = Math.abs(value.longValue()); else if (value instanceof Double) retval = Math.abs(value.doubleValue()); else if (value instanceof Float) retval = Math.abs(value.floatValue()); else if (value instanceof Integer) retval = Math.abs(value.intValue()); } catch (NumberFormatException nfe) { return (Number) Integer.MIN_VALUE; } return retval; }
From source file:com.sunchenbin.store.feilong.core.util.RandomUtil.java
/** * 0-?./*from ww w . j a v a2s.com*/ * * <p> * ??{@link #JVM_RANDOM} * </p> * * @param number * ? * @return 0-? * @see java.lang.Math#random() */ public static long createRandom(Number number) { double random = JVM_RANDOM.nextDouble(); return (long) Math.floor(random * number.longValue()); }
From source file:org.candlepin.common.config.PropertyConverter.java
public static Long toLong(Object value) throws ConversionException { Number n = toNumber(value, Long.class); if (n instanceof Long) { return (Long) n; } else {/*w w w. j av a 2s . co m*/ return new Long(n.longValue()); } }
From source file:Main.java
private static boolean compareScalarValues(Object myValue, Object otherValue) { if (myValue == null && otherValue != null || myValue != null && otherValue == null) return false; if (myValue == null) return true; if (myValue.getClass().isArray() && !otherValue.getClass().isArray() || !myValue.getClass().isArray() && otherValue.getClass().isArray()) return false; if (myValue.getClass().isArray() && otherValue.getClass().isArray()) { final int myArraySize = Array.getLength(myValue); final int otherArraySize = Array.getLength(otherValue); if (myArraySize != otherArraySize) return false; for (int i = 0; i < myArraySize; i++) if (!Array.get(myValue, i).equals(Array.get(otherValue, i))) return false; return true; }/* w ww . j a v a2 s .c om*/ if (myValue instanceof Number && otherValue instanceof Number) { final Number myNumberValue = (Number) myValue; final Number otherNumberValue = (Number) otherValue; if (isInteger(myNumberValue) && isInteger(otherNumberValue)) return myNumberValue.longValue() == otherNumberValue.longValue(); else if (isFloat(myNumberValue) && isFloat(otherNumberValue)) return myNumberValue.doubleValue() == otherNumberValue.doubleValue(); } return myValue.equals(otherValue); }
From source file:com.p5solutions.core.utils.NumberUtils.java
/** * Long value. Also checks for null/*from w w w .j av a2 s . c o m*/ * * @param number * the number * @return the long, returns null if param number is null */ public static Long longValue(Number number) { if (number != null) { return number.longValue(); } return null; }
From source file:org.candlepin.common.config.PropertyConverter.java
public static BigInteger toBigInteger(Object value) throws ConversionException { Number n = toNumber(value, BigInteger.class); if (n instanceof BigInteger) { return (BigInteger) n; } else {//from ww w . j a v a2 s. c om return BigInteger.valueOf(n.longValue()); } }
From source file:com.feilong.commons.core.util.RandomUtil.java
/** * 0-?.<br>/* w w w.j a va 2 s . c om*/ * <b>??{@link #JVM_RANDOM}</b> * * @param number * ? * @return 0-? */ public static long createRandom(Number number) { // double random = Math.random(); double random = JVM_RANDOM.nextDouble(); return (long) Math.floor(random * number.longValue()); }
From source file:com.alibaba.otter.manager.web.common.NumberFormatUtil.java
public static String formatFileSize(Number data) { if (data == null) { return null; }/* w w w . j a v a 2 s.c o m*/ long size = data.longValue(); if (size > TB_SIZE) { DecimalFormat format = new DecimalFormat(PATTERN); return format.format((size * 1.0) / TB_SIZE) + " TB"; } else if (size > GB_SIZE) { DecimalFormat format = new DecimalFormat(PATTERN); return format.format((size * 1.0) / GB_SIZE) + " GB"; } else if (size > MB_SIZE) { DecimalFormat format = new DecimalFormat(PATTERN); return format.format((size * 1.0) / MB_SIZE) + " MB"; } else if (size > KB_SIZE) { DecimalFormat format = new DecimalFormat(PATTERN); return format.format((size * 1.0) / KB_SIZE) + " KB"; } else { DecimalFormat format = new DecimalFormat(PATTERN); return format.format(size) + " B"; } }