Example usage for java.lang Double doubleValue

List of usage examples for java.lang Double doubleValue

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public double doubleValue() 

Source Link

Document

Returns the double value of this Double object.

Usage

From source file:JobBase.java

/**
 * Increment the given counter by the given incremental value If the counter
 * does not exist, one is created with value 0.
 * //from  w  ww .j a  v a  2 s  .c  o  m
 * @param name
 *          the counter name
 * @param inc
 *          the incremental value
 * @return the updated value.
 */
protected Double addDoubleValue(Object name, double inc) {
    Double val = this.doubleCounters.get(name);
    Double retv = null;
    if (val == null) {
        retv = new Double(inc);
    } else {
        retv = new Double(val.doubleValue() + inc);
    }
    this.doubleCounters.put(name, retv);
    return retv;
}

From source file:ome.util.ModelMapper.java

public double nullSafeDouble(Double d) {
    if (d == null) {
        return 0.0;
    }//w w  w  . j  a  v a 2  s .  com
    return d.doubleValue();
}

From source file:au.org.ala.ecodata.IniReader.java

/**
 *
 * @param section section name as String
 * @param key key name as String//  w w w .j ava2 s. c om
 * @return value of key as double
 *    0 when key is not found
 */
public double getDoubleValue(String section, String key) {
    String str = document.get(section + "\\" + key);
    Double ret;
    try {
        ret = new Double(str);
    } catch (Exception e) {
        ret = new Double(0);
    }
    return ret.doubleValue();
}

From source file:org.openo.nfvo.monitor.dac.common.util.Calculator.java

public List fcalculate(Map listMap, String formula, String[] variable) throws MonitorException {
    List retList = new ArrayList();
    Object obj = null;/*from w w w  .  j  a  v a2s .  c o  m*/
    try {
        JexlContext jexlContext = new MapContext();
        JexlEngine jexlEngine = new JexlEngine();
        Expression expression = jexlEngine.createExpression(formula);
        int sizej = ((List) (listMap.get(variable[0]))).size();
        // ?ist?         for (int j = 0; j < sizej; j++)
        {
            // ???
            for (int i = 0, sizei = variable.length; i < sizei; i++) {
                //jexlContext.set(variable[i], ((List) (listMap.get(variable[i]))).get(j));
                jexlContext.set(variable[i], ((List) (listMap.get(variable[i]))).get(i));
            }
            obj = expression.evaluate(jexlContext);
            if (obj instanceof Double) {
                Double dd = (Double) obj;
                double dd1 = (dd.doubleValue() * 1000);
                long ld1 = (long) dd1;
                double dd2 = ld1 / 1000.0;
                String sResult = Double.toString(dd2);
                retList.add(sResult);
            } else {
                throw new MonitorException("formular's result is not double type" + formula);
            }
        }

        return retList;
    } catch (Exception e) {
        throw new MonitorException(
                "parsing expression, or expression neither an expression or a reference! or evaluate error"
                        + e.getMessage());
    }
}

From source file:net.sourceforge.fenixedu.applicationTier.Servico.teacher.onlineTests.ReadDistributedTestMarksToString.java

protected String run(String executionCourseId, String distributedTestId) throws FenixServiceException {
    DistributedTest distributedTest = FenixFramework.getDomainObject(distributedTestId);
    if (distributedTest == null) {
        throw new InvalidArgumentsServiceException();
    }//from  ww  w . j  a  va2  s .com
    StringBuilder result = new StringBuilder();
    result.append(BundleUtil.getString(Bundle.APPLICATION, "label.username")).append("\t");
    result.append(BundleUtil.getString(Bundle.APPLICATION, "label.number")).append("\t");
    result.append(BundleUtil.getString(Bundle.APPLICATION, "label.name")).append("\t");
    for (int i = 1; i <= distributedTest.getNumberOfQuestions().intValue(); i++) {
        result.append("P").append(i).append("\t");
    }
    result.append(BundleUtil.getString(Bundle.APPLICATION, "label.grade")).append("\t");

    Double maximumMark = distributedTest.calculateMaximumDistributedTestMark();
    if (maximumMark.doubleValue() > 0) {
        result.append("\tNota (%)");
    }

    DecimalFormat df = new DecimalFormat("#0.##");
    DecimalFormat percentageFormat = new DecimalFormat("#%");

    for (Registration registration : distributedTest.findStudents()) {
        result.append("\n").append(registration.getPerson().getUsername());
        result.append("\t").append(registration.getNumber());
        result.append("\t");
        result.append(registration.getStudent().getPerson().getName());
        result.append("\t");
        Double finalMark = new Double(0);
        for (StudentTestQuestion studentTestQuestion : distributedTest.findStudentTestQuestions(registration)) {
            result.append(df.format(studentTestQuestion.getTestQuestionMark()));
            result.append("\t");
            finalMark = new Double(
                    finalMark.doubleValue() + studentTestQuestion.getTestQuestionMark().doubleValue());
        }
        if (finalMark.doubleValue() < 0) {
            result.append("0\t");
        } else {
            result.append(df.format(finalMark.doubleValue()));
            result.append("\t");
        }
        if (maximumMark.doubleValue() > 0) {
            double finalMarkPercentage = finalMark.doubleValue()
                    * java.lang.Math.pow(maximumMark.doubleValue(), -1);
            if (finalMarkPercentage < 0) {
                result.append("0%");
            } else {
                result.append(percentageFormat.format(finalMarkPercentage));
            }
        }
    }
    return result.toString();
}

From source file:com.amazonaws.util.TimingInfo.java

@Deprecated
public final double getTimeTakenMillis() {
    Double v = getTimeTakenMillisIfKnown();
    return v == null ? UNKNOWN : v.doubleValue();
}

From source file:com.aurel.track.fieldType.bulkSetters.DoubleBulkSetter.java

/**
 * Sets the workItemBean's attribute depending on the value and bulkRelation
 * @param workItemBean//from w ww. j a va  2s  . co  m
 * @param fieldID
 * @param parameterCode
 * @param bulkTranformContext
 * @param selectContext
 * @param value    
 * @return ErrorData if an error is found
 */
@Override
public ErrorData setWorkItemAttribute(TWorkItemBean workItemBean, Integer fieldID, Integer parameterCode,
        BulkTranformContext bulkTranformContext, SelectContext selectContext, Object value) {
    if (getRelation() == BulkRelations.SET_NULL) {
        workItemBean.setAttribute(fieldID, parameterCode, null);
        return null;
    }
    Double doubleValue = null;
    try {
        doubleValue = (Double) value;
    } catch (Exception e) {
        LOGGER.warn("Getting the double value for " + value + " failed with " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
    }
    switch (getRelation()) {
    case BulkRelations.SET_TO:
        workItemBean.setAttribute(fieldID, parameterCode, doubleValue);
        break;
    case BulkRelations.ADD_IF_SET:
        if (doubleValue != null) {
            Double originalValue = (Double) workItemBean.getAttribute(fieldID, parameterCode);
            if (originalValue != null) {
                double newValue = originalValue.doubleValue() + doubleValue.doubleValue();
                workItemBean.setAttribute(fieldID, parameterCode, Double.valueOf(newValue));
            }
        }
        break;
    case BulkRelations.ADD_OR_SET:
        if (doubleValue != null) {
            Double originalValue = (Double) workItemBean.getAttribute(fieldID, parameterCode);
            if (originalValue != null) {
                double newValue = originalValue.doubleValue() + doubleValue.doubleValue();
                workItemBean.setAttribute(fieldID, parameterCode, new Double(newValue));
            } else {
                workItemBean.setAttribute(fieldID, parameterCode, doubleValue);
            }
        }
        break;
    }
    return null;
}

From source file:com.ottogroup.bi.streaming.operator.json.aggregate.functions.DoubleContentAggregateFunction.java

/**
 * @see com.ottogroup.bi.streaming.operator.json.aggregate.functions.JsonContentAggregateFunction#average(org.apache.commons.lang3.tuple.MutablePair, java.io.Serializable)
 *///from ww w  .ja va 2 s. c o m
public MutablePair<Double, Integer> average(MutablePair<Double, Integer> sumAndCount, Double value)
        throws Exception {
    if (sumAndCount == null && value == null)
        return new MutablePair<>(Double.valueOf(0), Integer.valueOf(0));
    if (sumAndCount == null && value != null)
        return new MutablePair<>(Double.valueOf(value.doubleValue()), Integer.valueOf(1));
    if (sumAndCount != null && value == null)
        return sumAndCount;
    sumAndCount.setLeft(sumAndCount.getLeft().doubleValue() + value.doubleValue());
    sumAndCount.setRight(sumAndCount.getRight().intValue() + 1);
    return sumAndCount;
}

From source file:edu.umn.se.trap.db.orm.DatabaseAccessor.java

/**
 * Convert a monetary amount measured in a foreign currency to USD.
 * //from   w  w w . ja  v  a 2 s . c  o  m
 * @param currency
 * @param amount
 * @param date
 * @return
 * @throws TrapException
 */
public double getUsd(String currency, double amount, Date date) throws TrapException {
    try {
        if (StringUtils.equals(currency, "USD")) {
            return amount;
        } else {
            Double conversionRate = currencyDB.getConversion(currency, TrapDateUtil.printDate(date));
            return conversionRate.doubleValue() * amount;
        }

    } catch (KeyNotFoundException e) {
        throw new TrapException("Cannot find currency info");
    }
}

From source file:com.aurel.track.exchange.msProject.exchange.MsProjectExchangeBL.java

/**
 * Get hours from timeSpan//  w w w.j av  a2  s.co m
 *
 * @param timeUnitsMap
 * @return
 */
private static Double getHours(Map<String, Double> timeUnitsMap) {
    if (timeUnitsMap == null || timeUnitsMap.isEmpty()) {
        return null;
    }
    Double year = timeUnitsMap.get(MSPROJECT_TIME_UNITS.YEAR);
    Double month = timeUnitsMap.get(MSPROJECT_TIME_UNITS.MONTH);
    Double days = timeUnitsMap.get(MSPROJECT_TIME_UNITS.DAY);
    Double hours = timeUnitsMap.get(MSPROJECT_TIME_UNITS.HOUR);
    Double minutes = timeUnitsMap.get(MSPROJECT_TIME_UNITS.MINUTE);
    Double seconds = timeUnitsMap.get(MSPROJECT_TIME_UNITS.SECOND);
    double doubleHours = 0.0;
    if (year != null) {
        doubleHours += year.doubleValue() * 8 * 20 * 12;
    }
    if (month != null) {
        doubleHours += month.doubleValue() * 8 * 20;
    }
    if (days != null) {
        doubleHours += days.doubleValue() * 8;
    }
    if (hours != null) {
        doubleHours = hours.doubleValue();
    }
    if (minutes != null) {
        doubleHours += minutes.doubleValue() / 60;
    }
    if (seconds != null) {
        doubleHours += seconds.doubleValue() / (60 * 60);
    }
    return AccountingBL.roundToDecimalDigits(doubleHours, true);
}