Example usage for java.lang Double valueOf

List of usage examples for java.lang Double valueOf

Introduction

In this page you can find the example usage for java.lang Double valueOf.

Prototype

@HotSpotIntrinsicCandidate
public static Double valueOf(double d) 

Source Link

Document

Returns a Double instance representing the specified double value.

Usage

From source file:com.asprise.imaging.core.scan.twain.TwainUtil.java

/**
 * Extract the value represented by the given object (Number or String).
 * @param object the object to extract value from
 * @param defaultValue default value to be returned if object is null or {@linkplain NumberFormatException}.
 * @return the value extracted or default value if failed to extract the value.
 *//*from   ww  w  .  j  a v a2s  . co  m*/
public static int toInteger(Object object, int defaultValue) {
    if (object == null) {
        return defaultValue;
    }
    if (object instanceof Number) {
        return ((Number) object).intValue();
    }

    try {
        Double value = Double.valueOf(object.toString().trim());
        return value.intValue();
    } catch (NumberFormatException e) {
        return defaultValue;
    }
}

From source file:com.insightml.math.statistics.Correlation.java

@Override
public final int compareTo(final Correlation o) {
    return Double.valueOf(o.getMean()).compareTo(getMean());
}

From source file:de.hybris.platform.btg.validation.ExpressionValidatorTest.java

@Test
public void testCartTotalSum() {
    // no CartTotalSum expression
    BTGExpressionModel expression = createExpression(new BTGCartTotalSumOperandModel(),
            new BTGIntegerLiteralOperandModel());

    assertExpression(true, new CartTotalSumValidator(), expression);

    // negative value
    final BTGReferencePriceOperandModel rightOperandModel = new BTGReferencePriceOperandModel();
    rightOperandModel.setValue(Double.valueOf(-1));

    expression = createExpression(new BTGCartTotalSumOperandModel(), rightOperandModel);

    assertExpression(false, new CartTotalSumValidator(), expression);

    // zero/*from w  w w.  j a  v  a  2  s  . c o  m*/
    rightOperandModel.setValue(Double.valueOf(0));

    assertExpression(true, new CartTotalSumValidator(), expression);

    // positive value
    rightOperandModel.setValue(Double.valueOf(2));

    assertExpression(true, new CartTotalSumValidator(), expression);
}

From source file:msc.fall2015.stock.kmeans.hbase.mapreduce.StockDataReaderMapper.java

public void map(ImmutableBytesWritable row, Result value, Context context)
        throws InterruptedException, IOException {
    SimpleRegression regression;//from  ww w .  j  ava2s. c  o  m
    for (Map.Entry<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> columnFamilyMap : value.getMap()
            .entrySet()) {
        regression = new SimpleRegression();
        int count = 1;
        for (Map.Entry<byte[], NavigableMap<Long, byte[]>> entryVersion : columnFamilyMap.getValue()
                .entrySet()) {
            for (Map.Entry<Long, byte[]> entry : entryVersion.getValue().entrySet()) {
                String rowKey = Bytes.toString(value.getRow());
                String column = Bytes.toString(entryVersion.getKey());
                byte[] val = entry.getValue();
                String valOfColumn = new String(val);
                System.out.println(
                        "RowKey : " + rowKey + " Column Key : " + column + " Column Val : " + valOfColumn);
                if (!valOfColumn.isEmpty()) {
                    String[] priceAndCap = valOfColumn.split("_");
                    if (priceAndCap.length > 1) {
                        String pr = priceAndCap[0];
                        if (pr != null && !pr.equals("null")) {
                            double price = Double.valueOf(pr);
                            if (price < 0) {
                                price = price - 2 * price;
                            }
                            System.out.println("Price : " + price + " count : " + count);
                            regression.addData(count, price);
                        }
                    }
                }
            }
            count++;
        }
        // displays intercept of regression line
        System.out.println("Intercept : " + regression.getIntercept());

        // displays slope of regression line
        System.out.println("Slope : " + regression.getSlope());

        // displays slope standard error
        System.out.println("Slope STD Error : " + regression.getSlopeStdErr());
    }
}

From source file:edu.umich.robot.util.SimBattery.java

/**
 * @param mAh_max/*from  w  w w . j av a 2 s.  co  m*/
 * @param doc depth of charge
 */
public SimBattery(double mAh_max, double doc) {
    if (doc > 1.0 || doc < 0.1)
        doc = 1.0;
    if (mAh_max < 0)
        mAh_max = 10000;

    this.mAh_max = mAh_max;
    this.mAh = new AtomicReference<Double>(Double.valueOf(mAh_max));
    this.mAh_min = mAh_max * (1 - doc);

    logger.trace("Battery created with max " + mAh_max + " min " + mAh_min);

    start();
}

From source file:com.canalplus.reco.interactclient.InteractRestClient.java

/**
 * Convert list context en entree en event parameters de type
 * NameValuePairImp.//from ww w  . jav  a2s . c  o  m
 *
 * @param context
 * @return eventParameters
 */
private static NameValuePairImpl[] convertContext(List<Parametre> context) {
    final List<NameValuePairImpl> contextInteract = new ArrayList<NameValuePairImpl>();
    for (final Parametre parametre : context) {
        NameValuePairImpl contextParametre;
        if (Consts.DATA_TYPE_NAME_STRING.equals(parametre.getDataType())) {
            contextParametre = new NameValuePairImpl(parametre.getName(), NameValuePair.DATA_TYPE_STRING,
                    parametre.getValue());
        } else if (Consts.DATA_TYPE_NAME_NUMERIC.equals(parametre.getDataType())) {
            contextParametre = new NameValuePairImpl(parametre.getName(), NameValuePair.DATA_TYPE_NUMERIC,
                    Double.valueOf(parametre.getValue()));
        } else {
            contextParametre = new NameValuePairImpl(parametre.getName(), NameValuePair.DATA_TYPE_DATETIME,
                    parametre.getValue());
        }
        contextInteract.add(contextParametre);
    }
    final NameValuePairImpl[] eventParameters = new NameValuePairImpl[contextInteract.size()];
    contextInteract.toArray(eventParameters);
    return eventParameters;
}

From source file:com.spmadden.jnfsn.NFSNAccount.java

protected double getDouble(final String name) throws APIException {
    final String value = getString(name);
    return Double.valueOf(value);
}

From source file:com.nebhale.cyclinglibrary.web.PointControllerTest.java

@Test
public void readImage() {
    List<Point> points = Arrays.asList(new Point(Double.valueOf(0), Double.valueOf(1), Double.valueOf(2)));
    Item item = new Item(Long.valueOf(0), Long.valueOf(1), Long.valueOf(2), "test-name", "test-short-name",
            points);//from   ww w .  j a va2s  .c o  m
    when(this.itemRepository.read(Long.valueOf(2))).thenReturn(item);
    when(this.polylineEncoder.encodeSingle(1850, points)).thenReturn("encoded-polyline");

    ResponseEntity<Void> result = this.controller.read(Long.valueOf(2), "test-map-type", 100, 200,
            "test-user-ip");

    assertEquals(HttpStatus.SEE_OTHER, result.getStatusCode());
    assertEquals(URI.create(
            "http://maps.googleapis.com/maps/api/staticmap?key=test-google-api-key&sensor=false&userIp=test-user-ip&size=100x200&maptype=test-map-type&scale=2&path=color:0xff0000ff%7Cweight:2%7Cencoded-polyline"),
            result.getHeaders().getLocation());
}

From source file:com.workday.autoparse.xml.demo.XmlParserTest.java

@Test
public void testParse() throws UnknownElementException, ParseException, UnexpectedChildException {

    XmlStreamParser parser = XmlStreamParserFactory.newXmlStreamParser();

    InputStream in = getInputStreamOf("input.xml");
    DemoModel model = (DemoModel) parser.parseStream(in);

    assertTrue(model.myBoxedBoolean);/*w  ww  .  j av  a2  s  .com*/
    assertTrue(model.myPrimitiveBoolean);
    assertEquals(new BigDecimal(0.5), model.myBigDecimal);
    assertEquals(BigInteger.ONE, model.myBigInteger);
    assertEquals(2, model.myPrimitiveByte);
    assertEquals(Byte.valueOf((byte) 4), model.myBoxedByte);
    assertEquals('a', model.myPrimitiveChar);
    assertEquals(Character.valueOf('b'), model.myBoxedChar);
    assertEquals(5.5, model.myPrimitiveDouble, DOUBLE_E);
    assertEquals(Double.valueOf(6.5), model.myBoxedDouble);
    assertEquals(7.5f, model.myPrimitiveFloat, FLOAT_E);
    assertEquals(Float.valueOf(8.5f), model.myBoxedFloat);
    assertEquals(9, model.myPrimitiveInt);
    assertEquals(Integer.valueOf(10), model.myBoxedInt);
    assertEquals(11, model.myPrimitiveLong);
    assertEquals(Long.valueOf(12), model.myBoxedLong);
    assertEquals(13, model.myPrimitiveShort);
    assertEquals(Short.valueOf((short) 15), model.myBoxedShort);
    assertEquals("Bob", model.myString);
    assertTrue(model.myChildModel != null);

    assertEquals("My_String_Value", model.myChildModel.myString);
    assertEquals(5, model.myChildModel.myInt);

    assertEquals(3, model.repeatedChildModels.size());

    assertEquals("a", model.repeatedChildModels.get(0).value);
    assertEquals("I am some text.", model.repeatedChildModels.get(0).textContent);

    assertEquals("b", model.repeatedChildModels.get(1).value);
    assertNull(model.repeatedChildModels.get(1).textContent);

    assertEquals("c", model.repeatedChildModels.get(2).value);
}

From source file:org.spc.ofp.data.Repository.java

public static Double readDouble(final ResultSet rs, final String columnName) throws SQLException {
    final double value = rs.getDouble(columnName);
    return rs.wasNull() ? null : Double.valueOf(value);
}