Example usage for org.apache.commons.lang.math NumberUtils toDouble

List of usage examples for org.apache.commons.lang.math NumberUtils toDouble

Introduction

In this page you can find the example usage for org.apache.commons.lang.math NumberUtils toDouble.

Prototype

public static double toDouble(String str) 

Source Link

Document

Convert a String to a double, returning 0.0d if the conversion fails.

If the string str is null, 0.0d is returned.

 NumberUtils.toDouble(null)   = 0.0d NumberUtils.toDouble("")     = 0.0d NumberUtils.toDouble("1.5")  = 1.5d 

Usage

From source file:com.adaptris.core.services.jdbc.DoubleStatementParameter.java

Double toDouble(Object value) throws ServiceException {
    if (isBlank((String) value) && convertNull()) {
        return Double.valueOf(NumberUtils.toDouble((String) value));
    } else {/*from  w ww. j a  va  2 s. c  om*/
        return Double.valueOf((String) value);
    }
}

From source file:edu.cornell.med.icb.maps.LinkedHashToMultiTypeMap.java

/**
 * Returns the mapped value as a Double or null if the field doesn't exist in the map.
 * @param field the field to get/*from w w  w. ja  v a  2s. co m*/
 * @return the Double value for the field
 */
public Double getDouble(final T field) {
    final String value = get(field);
    if (value == null) {
        return null;
    }
    return NumberUtils.toDouble(value);
}

From source file:gemlite.core.internal.domain.utilClass.MqDataSource.java

public final double getDouble(String name) {
    String str = map.get(name);//from   ww w  .  ja  v  a 2s  . co  m
    double n = NumberUtils.toDouble(str);
    return n;
}

From source file:com.mobiaware.auction.provider.impl.CSVImportService.java

@Override
public void importItems(final int auctionUid, final Reader reader) throws IOException {
    CSVReader cvsreader = null;/*w ww  . jav  a  2s  .  co  m*/
    try {
        cvsreader = new CSVReader(reader, CSVParser.DEFAULT_SEPARATOR, CSVParser.DEFAULT_QUOTE_CHARACTER,
                CSVParser.DEFAULT_ESCAPE_CHARACTER, 0, false, false);

        List<String> headers = Arrays.asList(cvsreader.readNext());

        String[] nextLine;
        while ((nextLine = cvsreader.readNext()) != null) {
            _dataService.editItem(Item.newBuilder().setAuctionUid(auctionUid)
                    .setItemNumber(nextLine[headers.indexOf("number")])
                    .setName(nextLine[headers.indexOf("name")])
                    .setDescription(nextLine[headers.indexOf("description")])
                    .setCategory(nextLine[headers.indexOf("category")])
                    .setSeller(nextLine[headers.indexOf("seller")])
                    .setValPrice(NumberUtils.toDouble(nextLine[headers.indexOf("value")]))
                    .setMinPrice(NumberUtils.toDouble(nextLine[headers.indexOf("minimum")]))
                    .setIncPrice(NumberUtils.toDouble(nextLine[headers.indexOf("increment")]))
                    .setUrl(nextLine[headers.indexOf("image")]).build());
        }
    } finally {
        IOUtils.closeQuietly(cvsreader);
    }
}

From source file:com.intuit.tank.harness.functions.NumericFunctions.java

private static String add(String[] values, Variables variables) {
    double result = 0;
    for (int i = 3; i < values.length; i++) {
        if (values[i] != null) {
            result += NumberUtils.toDouble(values[i]);
        } else {/*from  w  w  w  .  j  a  v a2s  . c  o m*/
            break;
        }
    }
    return Double.toString(result);
}

From source file:com.intuit.tank.harness.functions.NumericFunctions.java

private static String subtract(String[] values, Variables variables) {
    Double result = null;//  w  w  w.ja  v  a2s . co m
    for (int i = 3; i < values.length; i++) {
        if (values[i] != null) {
            if (result == null) {
                result = NumberUtils.toDouble(values[i]);
            } else {
                result -= NumberUtils.toDouble(values[i]);
            }
        } else {
            break;
        }
    }
    return Double.toString(result);
}

From source file:edu.cornell.med.icb.maps.LinkedHashToMultiTypeMap.java

/**
 * Returns the mapped value as a double[] or null if the field doesn't exist in the map.
 * @param field the field to get/* www  . j  ava  2 s . c  o m*/
 * @param splitChar the char to split the doubles, often ',' or '\t' is a good choice.
 * @return the double[] value for the field
 */
public double[] getDoubleArray(final T field, final char splitChar) {
    final String value = get(field);
    if (value == null) {
        return null;
    }
    final String[] splits;
    if (value.indexOf(splitChar) != -1) {
        splits = StringUtils.split(value, splitChar);
    } else {
        return new double[] { getDouble(field) };
    }
    final double[] result = new double[splits.length];
    int i = 0;
    for (String split : splits) {
        if (StringUtils.isBlank(split)) {
            split = "0";
        }
        result[i++] = NumberUtils.toDouble(split.trim());
    }
    return result;
}

From source file:com.ace.capitalflows.ui.frame.chart.NianYdChart.java

/**
 * Creates a dataset, consisting of two series of monthly data.
 *
 * @return The dataset./*from   w w  w.  ja va2s. com*/
 */
private XYDataset createDataset() {

    final TimeSeries ydResi = new TimeSeries("YdResidual");
    for (int i = 0; dataArray[i] != null && i < dataArray.length - 1; i++) {
        final String nianYd = (String) dataArray[i][0];
        final int year = CommenUtils.parseNian(nianYd);
        final int m = CommenUtils.parseJDORYD(nianYd);
        ydResi.add(new Month(m, year), NumberUtils.toDouble((String) dataArray[i][1]));
    }

    // ******************************************************************
    //  More than 150 demo applications are included with the JFreeChart
    //  Developer Guide...for more information, see:
    //
    //  >   http://www.object-refinery.com/jfreechart/guide.html
    //
    // ******************************************************************

    final TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(ydResi);

    return dataset;

}

From source file:com.ace.capitalflows.ui.frame.chart.NianJdChart.java

/**
 * Creates a dataset, consisting of two series of monthly data.
 *
 * @return The dataset.//from   w w  w .  j a  va  2s.  c o  m
 */
private XYDataset createDataset() {

    final TimeSeries cudd = new TimeSeries("CuddingTon");
    final TimeSeries resi = new TimeSeries("Residual");
    for (int i = 0; dataArray[i] != null && i < dataArray.length - 1; i++) {
        final String nianJd = (String) dataArray[i][0];
        final int year = CommenUtils.parseNian(nianJd);
        final int jd = CommenUtils.parseJDORYD(nianJd);
        cudd.add(new Quarter(jd, year), NumberUtils.toDouble((String) dataArray[i][1]));
        resi.add(new Quarter(jd, year), NumberUtils.toDouble((String) dataArray[i][2]));
    }

    // ******************************************************************
    //  More than 150 demo applications are included with the JFreeChart
    //  Developer Guide...for more information, see:
    //
    //  >   http://www.object-refinery.com/jfreechart/guide.html
    //
    // ******************************************************************

    final TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(cudd);
    dataset.addSeries(resi);

    return dataset;

}

From source file:com.intuit.tank.harness.functions.NumericFunctionsTest.java

/**
 * Run the String randomNegativeFloat(int,int) method test.
 * //from ww  w .j a v  a  2  s  . c  o  m
 * @throws Exception
 * 
 * @generatedBy CodePro at 9/3/14 9:21 PM
 */
@Test
public void testRandomNegativeFloat_1() throws Exception {
    int whole = 1;
    int decimal = 1;

    String result = NumericFunctions.randomNegativeFloat(whole, decimal);

    assertTrue(NumberUtils.isNumber(result));
    assertTrue(NumberUtils.toDouble(result) < 0);
}