List of usage examples for java.lang Number doubleValue
public abstract double doubleValue();
From source file:org.jfree.data.DataUtilities.java
/** * Returns a {@link KeyedValues} instance that contains the cumulative * percentage values for the data in another {@link KeyedValues} instance. * <p>/*w ww . ja v a 2s . c o m*/ * The percentages are values between 0.0 and 1.0 (where 1.0 = 100%). * * @param data the data (<code>null</code> not permitted). * * @return The cumulative percentages. */ public static KeyedValues getCumulativePercentages(KeyedValues data) { ParamChecks.nullNotPermitted(data, "data"); DefaultKeyedValues result = new DefaultKeyedValues(); double total = 0.0; for (int i = 0; i < data.getItemCount(); i++) { Number v = data.getValue(i); if (v != null) { total = total + v.doubleValue(); } } double runningTotal = 0.0; for (int i = 0; i < data.getItemCount(); i++) { Number v = data.getValue(i); if (v != null) { runningTotal = runningTotal + v.doubleValue(); } result.addValue(data.getKey(i), new Double(runningTotal / total)); } return result; }
From source file:org.jfree.data.DataUtils.java
/** * Returns a {@link KeyedValues} instance that contains the cumulative * percentage values for the data in another {@link KeyedValues} instance. * <p>// ww w . ja v a 2 s.co m * The percentages are values between 0.0 and 1.0 (where 1.0 = 100%). * * @param data the data ({@code null} not permitted). * * @return The cumulative percentages. */ public static KeyedValues getCumulativePercentages(KeyedValues data) { Args.nullNotPermitted(data, "data"); DefaultKeyedValues result = new DefaultKeyedValues(); double total = 0.0; for (int i = 0; i < data.getItemCount(); i++) { Number v = data.getValue(i); if (v != null) { total = total + v.doubleValue(); } } double runningTotal = 0.0; for (int i = 0; i < data.getItemCount(); i++) { Number v = data.getValue(i); if (v != null) { runningTotal = runningTotal + v.doubleValue(); } result.addValue(data.getKey(i), new Double(runningTotal / total)); } return result; }
From source file:org.jfree.data.DataUtilities.java
/** * Returns the total of the values in one row of the supplied data * table by taking only the column numbers in the array into account. * * @param data the table of values (<code>null</code> not permitted). * @param row the row index (zero-based). * @param validCols the array with valid cols (zero-based). * * @return The total of the valid values in the specified row. * * @since 1.0.13/*from w ww . j a v a 2 s .c o m*/ */ public static double calculateRowTotal(Values2D data, int row, int[] validCols) { ParamChecks.nullNotPermitted(data, "data"); double total = 0.0; int colCount = data.getColumnCount(); for (int v = 0; v < validCols.length; v++) { int col = validCols[v]; if (col < colCount) { Number n = data.getValue(row, col); if (n != null) { total += n.doubleValue(); } } } return total; }
From source file:org.jfree.data.DataUtils.java
/** * Returns the total of the values in one row of the supplied data * table by taking only the column numbers in the array into account. * * @param data the table of values ({@code null} not permitted). * @param row the row index (zero-based). * @param validCols the array with valid cols (zero-based). * * @return The total of the valid values in the specified row. * * @since 1.0.13// w w w. j a v a2s . co m */ public static double calculateRowTotal(Values2D data, int row, int[] validCols) { Args.nullNotPermitted(data, "data"); double total = 0.0; int colCount = data.getColumnCount(); for (int v = 0; v < validCols.length; v++) { int col = validCols[v]; if (col < colCount) { Number n = data.getValue(row, col); if (n != null) { total += n.doubleValue(); } } } return total; }
From source file:org.jfree.data.DataUtilities.java
/** * Returns the total of the values in one column of the supplied data * table by taking only the row numbers in the array into account. * * @param data the table of values (<code>null</code> not permitted). * @param column the column index (zero-based). * @param validRows the array with valid rows (zero-based). * * @return The total of the valid values in the specified column. * * @since 1.0.13/* w w w . j ava2s . c o m*/ */ public static double calculateColumnTotal(Values2D data, int column, int[] validRows) { ParamChecks.nullNotPermitted(data, "data"); double total = 0.0; int rowCount = data.getRowCount(); for (int v = 0; v < validRows.length; v++) { int row = validRows[v]; if (row < rowCount) { Number n = data.getValue(row, column); if (n != null) { total += n.doubleValue(); } } } return total; }
From source file:org.jfree.data.DataUtils.java
/** * Returns the total of the values in one column of the supplied data * table by taking only the row numbers in the array into account. * * @param data the table of values ({@code null} not permitted). * @param column the column index (zero-based). * @param validRows the array with valid rows (zero-based). * * @return The total of the valid values in the specified column. * * @since 1.0.13//from w ww .j a v a2 s.c om */ public static double calculateColumnTotal(Values2D data, int column, int[] validRows) { Args.nullNotPermitted(data, "data"); double total = 0.0; int rowCount = data.getRowCount(); for (int v = 0; v < validRows.length; v++) { int row = validRows[v]; if (row < rowCount) { Number n = data.getValue(row, column); if (n != null) { total += n.doubleValue(); } } } return total; }
From source file:gedi.util.MathUtils.java
/** * Throws an exception if n is either a real or to big to be represented by a byte. * @param n/* w w w .j a va 2s. c o m*/ * @return */ public static long longValueExact(Number n) { if (n instanceof Long || n instanceof Integer || n instanceof Short || n instanceof Byte) return n.longValue(); double d = n.doubleValue(); long l = n.longValue(); if (d == (double) l) { return l; } throw new NumberFormatException(); }
From source file:edu.uci.ics.jung.algorithms.shortestpath.DistanceStatistics.java
/** * Returns the diameter of <code>g</code> using the metric * specified by <code>d</code>. The diameter is defined to be * the maximum, over all pairs of vertices <code>u,v</code>, * of the length of the shortest path from <code>u</code> to * <code>v</code>. If the graph is disconnected (that is, not * all pairs of vertices are reachable from one another), the * value returned will depend on <code>use_max</code>: * if <code>use_max == true</code>, the value returned * will be the the maximum shortest path length over all pairs of <b>connected</b> * vertices; otherwise it will be <code>Double.POSITIVE_INFINITY</code>. *//*from w w w . ja va 2 s. co m*/ public static <V, E> double diameter(Hypergraph<V, E> g, Distance<V> d, boolean use_max) { double diameter = 0; Collection<V> vertices = g.getVertices(); for (V v : vertices) { for (V w : vertices) { if (v.equals(w) == false) // don't include self-distances { Number dist = d.getDistance(v, w); if (dist == null) { if (!use_max) return Double.POSITIVE_INFINITY; } else diameter = Math.max(diameter, dist.doubleValue()); } } } return diameter; }
From source file:com.bitsofproof.example.Simple.java
public static long parseBit(String s) throws ParseException { Number n = NumberFormat.getNumberInstance().parse(s); if (n instanceof Double) { return (long) (n.doubleValue() * 100.0); } else {/*from ww w .j a v a 2 s . c o m*/ return n.longValue() * 100; } }
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 a v a2s . 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; }