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.qcadoo.model.api.BigDecimalUtils.java

/**
 * Converts value, if null returns zero//from  w ww .java 2s  .  com
 * 
 * @param value
 *            value
 * 
 * @return value or zero
 */
public static BigDecimal convertNullToZero(final Object value) {
    if (value == null) {
        return BigDecimal.ZERO;
    }
    if (value instanceof BigDecimal) {
        return (BigDecimal) value;
    }
    return BigDecimal.valueOf(Double.valueOf(value.toString()));
}

From source file:net.ceos.project.poi.annotated.bean.ConditionalFormatObjectBuilder.java

/**
 * Create a ConditionalFormatObject for tests.
 * /* w  ww.j  av a2 s . c  om*/
 * @return the {@link ConditionalFormatObject}
 */
public static ConditionalFormatObject buildConditionalFormatObject(int multiplier) {
    ConditionalFormatObject toValidate = new ConditionalFormatObject();

    toValidate.setDateAttribute(new Date());
    toValidate.setStringAttribute("Cascade L2");
    toValidate.setIntegerAttribute(46 * multiplier);
    toValidate.setDoubleAttribute(Double.valueOf("25.3") * multiplier);
    toValidate.setLongAttribute(Long.valueOf("1234567890") * multiplier);
    toValidate.setBooleanAttribute(Boolean.FALSE);
    /* create sub object Job */
    Job job = new Job();
    job.setJobCode(0005);
    job.setJobFamily("Family Job Name L2");
    job.setJobName("Job Name L2");
    toValidate.setJob(job);

    return toValidate;
}

From source file:Main.java

/**
 * Converts to object array./*from w w w  .j a va2  s . c  o m*/
 */
public static Double[] valuesOf(double[] array) {
    Double[] dest = new Double[array.length];
    for (int i = 0; i < array.length; i++) {
        dest[i] = Double.valueOf(array[i]);
    }
    return dest;
}

From source file:com.alibaba.doris.admin.service.impl.ValueParseUtil.java

/**
 * ?,?,//  w w  w  .ja v a  2 s.  com
 * 
 * @param clazz
 * @return
 */
@SuppressWarnings("unchecked")
private static <T> T getInternalDefaultValue(Class<T> clazz) {
    if (!clazz.isPrimitive()) {
        return null;
    }
    if (Short.TYPE.equals(clazz)) {
        return (T) Short.valueOf((short) 0);
    }
    if (Integer.TYPE.equals(clazz)) {
        return (T) Integer.valueOf(0);
    }
    if (Long.TYPE.equals(clazz)) {
        return (T) Long.valueOf(0);
    }
    if (Boolean.TYPE.equals(clazz)) {
        return (T) Boolean.valueOf(false);
    }
    if (Float.TYPE.equals(clazz)) {
        return (T) Float.valueOf(0);
    }
    if (Double.TYPE.equals(clazz)) {
        return (T) Double.valueOf(0);
    }
    if (Byte.TYPE.equals(clazz)) {
        return (T) Byte.valueOf((byte) 0);
    }
    if (Character.TYPE.equals(clazz)) {
        return (T) Character.valueOf('\0');
    }
    return null;
}

From source file:org.jfree.graphics2d.demo.CanvasPieChartDemo1.java

/**
 * Creates a sample dataset.//from ww w. j ava2  s . c  o  m
 *
 * @return A sample dataset.
 */
private static PieDataset createDataset() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("One", Double.valueOf(43.2));
    dataset.setValue("Two", Double.valueOf(10.0));
    dataset.setValue("Three", Double.valueOf(27.5));
    dataset.setValue("Four", Double.valueOf(17.5));
    dataset.setValue("Five", Double.valueOf(11.0));
    dataset.setValue("Six", Double.valueOf(19.4));
    return dataset;
}

From source file:com.linkedin.pinot.tools.query.comparison.StatsGenerator.java

public static void generateReport(String dataFileName) throws IOException {
    List<DescriptiveStatistics> statisticsList = new ArrayList<>();

    String dataString;//ww  w .  j  av a2 s.  co m
    BufferedReader dataReader = new BufferedReader(new FileReader(dataFileName));

    // First line is treated as header
    String[] columns = dataReader.readLine().split("\\s+");
    int numColumns = columns.length;

    for (int i = 0; i < numColumns; ++i) {
        statisticsList.add(new DescriptiveStatistics());
    }

    while ((dataString = dataReader.readLine()) != null) {
        String[] dataArray = dataString.trim().split(" ");

        if (dataArray.length != numColumns) {
            throw new RuntimeException("Row has missing columns: " + Arrays.toString(dataArray) + " Expected: "
                    + numColumns + " columns.");
        }

        for (int i = 0; i < dataArray.length; ++i) {
            double data = Double.valueOf(dataArray[i]);
            statisticsList.get(i).addValue(data);
        }
    }

    for (int i = 0; i < numColumns; i++) {
        LOGGER.info("Stats: {}: {}", columns[i], statisticsList.get(i).toString().replace("\n", "\t"));
    }
}

From source file:hyperheuristics.algorithm.moeadfrrmab.UCBSelectorVariance.java

protected double calcVariance(String op) {
    ArrayList<String[]> slOp = slidingwindow.getWindowforOp(op);
    if (slOp.size() > 1) {
        ArrayList<Double> values = new ArrayList<>();
        for (int i = 0; i < slOp.size(); i++) {
            String[] data = slOp.get(i);
            double FIR = Double.valueOf(data[1]);
            values.add(FIR);/*from   w  w w.  j  a  v a 2 s .  c  o  m*/
        }
        double[] arr = ArrayUtils.toPrimitive(values.toArray(new Double[0]));
        return this.calcVariance(arr);
    }
    return 1.0;
}

From source file:de.hybris.platform.acceleratorservices.dataimport.batch.converter.PriceTranslator.java

@Override
public Object importValue(final String valueExpr, final Item toItem) throws JaloInvalidParameterException {
    clearStatus();/*  ww  w. j a  va  2s .  c  o m*/
    Double result = null;
    if (!StringUtils.isBlank(valueExpr)) {
        try {
            result = Double.valueOf(valueExpr);
        } catch (final NumberFormatException exc) {
            setError();
        }
        if (result != null && result.doubleValue() < 0.0) {
            setError();
        }
    }
    return result;
}

From source file:automaticdatabaseupdate.FileHandler.java

/**
 *
 * @param strFilePath    - path of given file          e.g. "D:\\EGYETEM\\Szakdolgozat\\Mernoki_tervezes\\update files\\sr28upd\\ADD_NUTR.txt"
 * @param strFileType    - type of the given file      e.g. AddFood
 * @param TList          - list to fill with data      e.g. List<FileFoodStruct> ListFFS
 *//*from  ww w  .j  a va  2  s . c  om*/
public static <T> void readFile(String strFilePath, List<T> TList, String strFileType) {
    TList.clear();

    try {

        File file = FileUtils.getFile(strFilePath);
        LineIterator iter = FileUtils.lineIterator(file);

        while (iter.hasNext()) {
            String strLine = iter.next();

            switch (strFileType) {
            case "ADD_FOOD": {
                ArrayList<String> strList = ParseUpdateFile(strLine);
                FileFoodStruct Object = new FileFoodStruct(Integer.valueOf(strList.get(0)), strList.get(2),
                        strList.get(3), Integer.valueOf(strList.get(8)));
                TList.add((T) Object);
                System.out.println(Object.toString());
                break;
            }
            case "ADD_NUTR": {
                ArrayList<String> strList = ParseUpdateFile(strLine);
                FileNutrientStruct Object = new FileNutrientStruct(Integer.valueOf(strList.get(0)),
                        Integer.valueOf(strList.get(1)), Double.valueOf(strList.get(2)));
                TList.add((T) Object);
                System.out.println(Object.toString());
                break;
            }
            case "ADD_WGT": {
                ArrayList<String> strList = ParseUpdateFile(strLine);
                FileWeightStruct Object = new FileWeightStruct(Integer.valueOf(strList.get(0)),
                        Double.valueOf(strList.get(2)), strList.get(3), Double.valueOf(strList.get(4)));
                TList.add((T) Object);
                System.out.println(Object.toString());
                break;
            }
            case "CHG_FOOD": {
                ArrayList<String> strList = ParseUpdateFile(strLine);
                FileFoodStruct Object = new FileFoodStruct(Integer.valueOf(strList.get(0)), strList.get(2),
                        strList.get(3), Integer.valueOf(strList.get(8)));
                TList.add((T) Object);
                System.out.println(Object.toString());
                break;
            }
            case "CHG_NUTR": {
                ArrayList<String> strList = ParseUpdateFile(strLine);
                FileNutrientStruct Object = new FileNutrientStruct(Integer.valueOf(strList.get(0)),
                        Integer.valueOf(strList.get(1)), Double.valueOf(strList.get(2)));
                TList.add((T) Object);
                System.out.println(Object.toString());
                break;
            }
            case "CHG_WGT": {
                ArrayList<String> strList = ParseUpdateFile(strLine);
                FileWeightStruct Object = new FileWeightStruct(Integer.valueOf(strList.get(0)),
                        Double.valueOf(strList.get(2)), strList.get(3), Double.valueOf(strList.get(4)));
                TList.add((T) Object);
                System.out.println(Object.toString());
                break;
            }
            case "DEL_FOOD": {
                ArrayList<String> strList = ParseUpdateFile(strLine);
                FileFoodStruct Object = new FileFoodStruct(Integer.valueOf(strList.get(0)), strList.get(1));
                TList.add((T) Object);
                System.out.println(Object.toString());
                break;
            }
            case "DEL_NUTR": {
                ArrayList<String> strList = ParseUpdateFile(strLine);
                FileNutrientStruct Object = new FileNutrientStruct(Integer.valueOf(strList.get(0)),
                        Integer.valueOf(strList.get(1)));
                TList.add((T) Object);
                System.out.println(Object.toString());
                break;
            }
            case "DEL_WGT": {
                ArrayList<String> strList = ParseUpdateFile(strLine);
                FileWeightStruct Object = new FileWeightStruct(Integer.valueOf(strList.get(0)),
                        Double.valueOf(strList.get(2)), strList.get(3), Double.valueOf(strList.get(4)));
                TList.add((T) Object);
                System.out.println(Object.toString());
                break;
            }
            case "LOG_FILE": {
                ArrayList<String> strList = ParseLogFile(strLine);
                TraceMessage Object = new TraceMessage(strList.get(0), strList.get(1));
                TList.add((T) Object);
                break;
            }
            }
        }
        //System.out.println( "Total line: " + moduleCounter );
        iter.close();

    } catch (IOException ex) {
        Logger.getLogger(FileHandler.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:net.ceos.project.poi.annotated.bean.MultiTypeObjectBuilder.java

/**
 * Create a MultiTypeObject for tests.//from ww  w  .ja v  a 2s. co  m
 * 
 * @return the {@link MultiTypeObject}
 */
public static MultiTypeObject buildMultiTypeObject(int multiplier) {
    MultiTypeObject toValidate = new MultiTypeObject();

    toValidate.setDateAttribute(new Date());
    toValidate.setLocalDateAttribute(LocalDate.now());
    toValidate.setLocalDateTimeAttribute(LocalDateTime.now());
    toValidate.setStringAttribute("some string");
    toValidate.setIntegerAttribute(46 * multiplier);
    toValidate.setDoubleAttribute(Double.valueOf("25.3") * multiplier);
    toValidate.setLongAttribute(Long.valueOf("1234567890") * multiplier);
    toValidate.setBooleanAttribute(Boolean.FALSE);
    /* create sub object Job */
    Job job = new Job();
    job.setJobCode(0005);
    job.setJobFamily("Family Job Name");
    job.setJobName("Job Name");
    toValidate.setJob(job);
    toValidate.setIntegerPrimitiveAttribute(121 * multiplier);
    toValidate.setDoublePrimitiveAttribute(44.6 * multiplier);
    toValidate.setLongPrimitiveAttribute(987654321L * multiplier);
    toValidate.setBooleanPrimitiveAttribute(true);
    /* create sub object AddressInfo */
    AddressInfo ai = new AddressInfo();
    ai.setAddress("this is the street");
    ai.setNumber(99);
    ai.setCity("this is the city");
    ai.setCityCode(70065);
    ai.setCountry("This is a Country");
    toValidate.setAddressInfo(ai);
    toValidate.setFloatAttribute(14.765f * multiplier);
    toValidate.setFloatPrimitiveAttribute(11.1125f * multiplier);
    toValidate.setUnitFamily(UnitFamily.COMPONENTS);
    toValidate.setBigDecimalAttribute(BigDecimal.valueOf(24.777).multiply(BigDecimal.valueOf(multiplier)));
    toValidate.setShortAttribute((short) 17);
    toValidate.setShortPrimitiveAttribute((short) 4);
    // TODO add new fields below

    return toValidate;
}