List of usage examples for java.lang Double Double
@Deprecated(since = "9") public Double(String s) throws NumberFormatException
From source file:Main.java
/** * Divides num1 by num2, and return the result in the correct number class. * // w w w.j ava2 s. c o m * @param num1 numerator * @param num2 denominator * @return num1/num2 in the most appropriate class */ static Number divide(Number num1, Number num2) { Number[] both = new Number[2]; both[0] = num1; both[1] = num2; Number division = (Number) getObject(both); if (division == null) { return null; } //Integer, Long, Float, Double if (division instanceof Integer) { //we've got 2 integers, but we're going to use double anyways return new Double(num1.doubleValue() / num2.doubleValue()); } else if (division instanceof Long) { return new Long(num1.longValue() / num2.longValue()); } else if (division instanceof Float) { return new Float(num1.floatValue() / num2.floatValue()); } else if (division instanceof Double) { return new Double(num1.doubleValue() / num2.doubleValue()); } else { return null; } }
From source file:com.appleframework.jmx.core.util.CoreUtils.java
public static Number valueOf(String value, String dataType) { if (dataType.equals("java.lang.Integer") || dataType.equals("int")) { return new Integer(value); }/* w ww . j a v a 2 s. c om*/ if (dataType.equals("java.lang.Double") || dataType.equals("double")) { return new Double(value); } if (dataType.equals("java.lang.Long") || dataType.equals("long")) { return new Long(value); } if (dataType.equals("java.lang.Float") || dataType.equals("float")) { return new Double(value); } if (dataType.equals("java.lang.Short") || dataType.equals("short")) { return new Short(value); } if (dataType.equals("java.lang.Byte") || dataType.equals("byte")) { return new Byte(value); } if (dataType.equals("java.math.BigInteger")) { return new BigInteger(value); } if (dataType.equals("java.math.BigDecimal")) { return new BigDecimal(value); } return null; }
From source file:datavis.BarGraph.java
public void addData(String sliceName, double dataIn, String typeIn) { barDataSet.setValue(new Double(dataIn), typeIn, sliceName); }
From source file:org.epsilonlabs.workflow.execution.example.GraphOutput.java
public GraphOutput(String appname, String graphname, String x, String y) { super(appname); barChart = ChartFactory.createBarChart(graphname, x, y, dataset, PlotOrientation.VERTICAL, false, true, false);// www . ja v a 2 s. c om ChartPanel chartPanel = new ChartPanel(barChart); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); int width = new Double(screenSize.getWidth()).intValue() - 100; chartPanel.setMaximumDrawHeight(500); chartPanel.setMaximumDrawWidth(width); chartPanel.setPreferredSize(new java.awt.Dimension(width, 500)); setContentPane(chartPanel); Font font = new Font("Dialog", Font.PLAIN, 15); barChart.getCategoryPlot().getDomainAxis().setTickLabelFont(font); barChart.getCategoryPlot().setColumnRenderingOrder(SortOrder.DESCENDING); }
From source file:com.joptimizer.algebra.CholeskyComparisonTest.java
/** * Test with a generic sparse matrix./*from w w w. j av a2s .com*/ */ public void testCompareFactorizations1() throws Exception { log.debug("testCompareFactorizations1"); int iterations = 4; int m = 1000; int dim = m * m; DoubleMatrix2D sMatrix = Utils.randomValuesSparseMatrix(m, m, -10, 10, 0.97, 12345L); //log.debug("sMatrix: " + Utils.toString(sMatrix.toArray())); DoubleMatrix2D QMatrix = Algebra.DEFAULT.mult(sMatrix, Algebra.DEFAULT.transpose(sMatrix));//positive and symmetric double[][] QMatrixData = QMatrix.toArray(); //log.debug("QMatrix: " + Utils.toString(QMatrix.toArray())); RealMatrix A = MatrixUtils.createRealMatrix(QMatrix.toArray()); log.debug("cardinality: " + QMatrix.cardinality()); int nz = dim - QMatrix.cardinality(); log.debug("sparsity index: " + 100 * new Double(nz) / dim + " %"); //try Cholesky 1 long t1F = System.currentTimeMillis(); CholeskyFactorization myc1 = null; for (int i = 0; i < iterations; i++) { //factorization myc1 = new CholeskyFactorization(QMatrix); myc1.factorize(); } log.debug("Cholesky standard factorization time: " + (System.currentTimeMillis() - t1F)); RealMatrix L1 = MatrixUtils.createRealMatrix(myc1.getL().toArray()); double norm1 = A.subtract(L1.multiply(L1.transpose())).getNorm(); log.debug("norm1 : " + norm1); assertEquals(0., norm1, 1.E-12 * Math.sqrt(dim)); long t1I = System.currentTimeMillis(); for (int i = 0; i < iterations; i++) { //inversion myc1.getInverse(); } log.debug("Cholesky standard inversion time : " + (System.currentTimeMillis() - t1I)); RealMatrix AInv1 = MatrixUtils.createRealMatrix(myc1.getInverse().toArray()); //try Cholesky 2 long t2F = System.currentTimeMillis(); CholeskyRCTFactorization myc2 = null; for (int i = 0; i < iterations; i++) { //factorization myc2 = new CholeskyRCTFactorization(QMatrix); myc2.factorize(); } log.debug("Cholesky RCT factorization time : " + (System.currentTimeMillis() - t2F)); RealMatrix L2 = MatrixUtils.createRealMatrix(myc2.getL().toArray()); double norm2 = A.subtract(L2.multiply(L2.transpose())).getNorm(); log.debug("norm2 : " + norm2); assertEquals(0., norm2, 1.E-12 * Math.sqrt(dim)); assertEquals(0., L1.subtract(L2).getNorm(), 1.E-10 * Math.sqrt(dim)); long t2I = System.currentTimeMillis(); for (int i = 0; i < iterations; i++) { //inversion myc2.getInverse(); } log.debug("Cholesky RCT inversion time : " + (System.currentTimeMillis() - t2I)); RealMatrix AInv2 = MatrixUtils.createRealMatrix(myc2.getInverse().toArray()); assertEquals(0., AInv1.subtract(AInv2).getNorm(), 1.E-10 * Math.sqrt(dim)); //try Cholesky 3 long t3F = System.currentTimeMillis(); CholeskyRCFactorization myc3 = null; for (int i = 0; i < iterations; i++) { //factorization myc3 = new CholeskyRCFactorization(QMatrix); myc3.factorize(); } log.debug("Cholesky RC factorization time : " + (System.currentTimeMillis() - t3F)); RealMatrix L3 = MatrixUtils.createRealMatrix(myc3.getL().toArray()); double norm3 = A.subtract(L3.multiply(L3.transpose())).getNorm(); log.debug("norm3 : " + norm3); assertEquals(0., norm3, 1.E-12 * Math.sqrt(dim)); assertEquals(0., L1.subtract(L3).getNorm(), 1.E-10 * Math.sqrt(dim)); long t3I = System.currentTimeMillis(); for (int i = 0; i < iterations; i++) { //inversion myc3.getInverse(); } log.debug("Cholesky RC inversion time : " + (System.currentTimeMillis() - t3I)); RealMatrix AInv3 = MatrixUtils.createRealMatrix(myc3.getInverse().toArray()); assertEquals(0., AInv1.subtract(AInv3).getNorm(), 1.E-10 * Math.sqrt(dim)); //try Cholesky 4 long t4 = System.currentTimeMillis(); LDLTFactorization myc4 = null; for (int i = 0; i < iterations; i++) { myc4 = new LDLTFactorization(new DenseDoubleMatrix2D(QMatrixData)); myc4.factorize(); } log.debug("Cholesky LDLT factorization time : " + (System.currentTimeMillis() - t4)); RealMatrix L4 = MatrixUtils.createRealMatrix(myc4.getL().toArray()); RealMatrix D4 = MatrixUtils.createRealMatrix(myc4.getD().toArray()); double norm4 = A.subtract(L4.multiply(D4.multiply(L4.transpose()))).getNorm(); log.debug("norm4 : " + norm4); assertEquals(0., norm4, 1.E-12 * Math.sqrt(dim)); //try Cholesky 5 long t5 = System.currentTimeMillis(); CholeskySparseFactorization myc5 = null; for (int i = 0; i < iterations; i++) { myc5 = new CholeskySparseFactorization(new SparseDoubleMatrix2D(QMatrix.toArray())); myc5.factorize(); } log.debug("Cholesky sparse factorization time : " + (System.currentTimeMillis() - t5)); RealMatrix L5 = MatrixUtils.createRealMatrix(myc5.getL().toArray()); double norm5 = A.subtract(L5.multiply(L5.transpose())).getNorm(); log.debug("norm5 : " + norm5); assertEquals(0., norm5, 1.E-12 * Math.sqrt(dim)); assertEquals(0., L1.subtract(L5).getNorm(), 1.E-10 * Math.sqrt(dim)); }
From source file:org.jfree.chart.demo.Performance2.java
/** * Creates a Number object every time the primitive is accessed - should be really slow. * * @return creates and returns a Number object. */// w ww . j a va2s . co m public Number getPrimitiveAsObject() { return new Double(this.primitive); }
From source file:MutableDouble.java
/** * Gets the value as a Double instance.//from w w w . j a v a2 s .c o m * * @return the value as a Double */ public Object getValue() { return new Double(this.value); }
From source file:com.likethecolor.alchemy.api.entity.AbstractAlchemyEntityTest.java
@Test public void testEquals() { final Double score = 12321.123131D; final AbstractAlchemyEntity entity = new MockAbstractAlchemyEntity(score); assertFalse(entity.equals(null));// w w w . j av a2 s . co m assertFalse(entity.equals(new Double(1312D))); assertTrue(entity.equals(entity)); assertEquals(entity, entity); assertSame(entity, entity); final AbstractAlchemyEntity other = new MockAbstractAlchemyEntity(score); assertTrue(entity.equals(other)); assertEquals(entity, other); assertNotSame(entity, other); // score other.setScore(score); assertTrue(entity.equals(other)); assertEquals(entity, other); assertNotSame(entity, other); }
From source file:Main.java
/** * Returns the value of a named node attribute in the form of a long * @param node The node to retrieve the attribute from * @param name The name of the attribute * @param defaultValue The default value if the attribute cannot be located or converted. * @return a long//w w w . java 2 s. co m */ public static long getAttributeByName(Node node, String name, long defaultValue) { if (node == null || name == null) return defaultValue; try { return new Double(getAttributeValueByName(node, name).trim()).longValue(); } catch (Exception e) { return defaultValue; } }
From source file:PieChartDemo1.java
/** * Creates a sample dataset.// w ww. j a v a 2 s.c o m * * Source: http://www.bbc.co.uk/news/business-15489523 * * @return A sample dataset. */ private static PieDataset createDataset() { DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("Samsung", new Double(27.8)); dataset.setValue("Others", new Double(55.3)); dataset.setValue("Nokia", new Double(16.8)); dataset.setValue("Apple", new Double(17.1)); return dataset; }