List of usage examples for java.lang Number doubleValue
public abstract double doubleValue();
From source file:NumberUtils.java
/** * Converts the given number to a <code>Double</code> (by using <code>doubleValue()</code>). * * @param number//from w w w.j a v a 2s. com * @return java.lang.Double */ public static Double toDouble(Number number) { return number == null || number instanceof Double ? (Double) number : new Double(number.doubleValue()); }
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 w w . j av a 2 s. c o m*/ 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:fr.gael.dhus.olingo.v1.visitor.functors.Transformers.java
/** unary minus. */ public static Transformer<Number, Number> minus() { return new Transformer<Number, Number>() { @Override/*from w w w . jav a 2 s. co m*/ public Number transform(Number u) { return -(u.doubleValue()); } }; }
From source file:com.adobe.acs.commons.mcp.util.AnnotatedFieldDeserializer.java
@SuppressWarnings("squid:S3776") private static Object convertPrimitiveValue(String value, Class<?> type) throws ParseException { if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) { return value.toLowerCase().trim().equals("true"); } else {//from w w w . j ava 2 s . co m NumberFormat numberFormat = NumberFormat.getNumberInstance(); Number num = numberFormat.parse(value); if (type.equals(Byte.class) || type.equals(Byte.TYPE)) { return num.byteValue(); } else if (type.equals(Double.class) || type.equals(Double.TYPE)) { return num.doubleValue(); } else if (type.equals(Float.class) || type.equals(Float.TYPE)) { return num.floatValue(); } else if (type.equals(Integer.class) || type.equals(Integer.TYPE)) { return num.intValue(); } else if (type.equals(Long.class) || type.equals(Long.TYPE)) { return num.longValue(); } else if (type.equals(Short.class) || type.equals(Short.TYPE)) { return num.shortValue(); } else { return null; } } }
From source file:net.sf.jasperreports.functions.standard.MathFunctions.java
/** * Returns the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer *///from w ww.j ava 2s .c o m @Function("CEIL") @FunctionParameters({ @FunctionParameter("number") }) public static Double CEIL(Number number) { if (number == null) { logNullArgument(); return null; } return Math.ceil(number.doubleValue()); }
From source file:net.sf.jasperreports.functions.standard.MathFunctions.java
/** * Returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer. *///ww w . j a va 2 s. c om @Function("FLOOR") @FunctionParameters({ @FunctionParameter("number") }) public static Double FLOOR(Number number) { if (number == null) { logNullArgument(); return null; } return Math.floor(number.doubleValue()); }
From source file:net.sf.jasperreports.functions.standard.MathFunctions.java
/** * Returns the positive square root of a number. The number must be positive. *///w w w .ja v a 2 s. c o m @Function("SQRT") @FunctionParameters({ @FunctionParameter("number") }) public static Number SQRT(Number number) { if (number == null) { logNullArgument(); return null; } else { return Math.sqrt(number.doubleValue()); } }
From source file:net.sf.jasperreports.functions.standard.MathFunctions.java
/** * Returns the sign of a number./* www .j a v a2 s . co m*/ */ @Function("SIGN") @FunctionParameters({ @FunctionParameter("number") }) public static Integer SIGN(Number number) { if (number == null) { logNullArgument(); return null; } else { return (int) Math.signum(number.doubleValue()); } }
From source file:com.github.rinde.rinsim.scenario.measure.Metrics.java
static StatisticalSummary toStatisticalSummary(Iterable<? extends Number> values) { final SummaryStatistics ss = new SummaryStatistics(); for (final Number n : values) { ss.addValue(n.doubleValue()); }//from ww w . j a va 2s .c om return ss.getSummary(); }
From source file:org.jfree.data.statistics.Statistics.java
/** * Returns the mean of a collection of {@code Number} objects. * * @param values the values ({@code null} not permitted). * @param includeNullAndNaN a flag that controls whether or not * {@code null} and {@code Double.NaN} values are included * in the calculation (if either is present in the array, the result is * {@link Double#NaN})./*from www. j ava 2s.c o m*/ * * @return The mean. * * @since 1.0.3 */ public static double calculateMean(Collection values, boolean includeNullAndNaN) { ParamChecks.nullNotPermitted(values, "values"); int count = 0; double total = 0.0; Iterator iterator = values.iterator(); while (iterator.hasNext()) { Object object = iterator.next(); if (object == null) { if (includeNullAndNaN) { return Double.NaN; } } else { if (object instanceof Number) { Number number = (Number) object; double value = number.doubleValue(); if (Double.isNaN(value)) { if (includeNullAndNaN) { return Double.NaN; } } else { total = total + number.doubleValue(); count = count + 1; } } } } return total / count; }