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.effektif.workflow.api.types.NumberType.java

/**
 * Parse a text value as a Integer, Long or Double, as appropriate.
 * Based on com.fasterxml.jackson.databind.deser.std.NumberDeserializers.NumberDeserializer#deserialize(JsonParser, DeserializationContext)
 *///from  ww w  .  jav a  2 s .  c  om
private Number parseValue(String value) {
    if (value == null) {
        return null;
    }
    value = value.trim();
    try {
        boolean decimal = value.contains(".");
        if (decimal) {
            return Double.valueOf(value);
        } else {
            long longValue = Long.parseLong(value);
            if (longValue <= Integer.MAX_VALUE && longValue >= Integer.MIN_VALUE) {
                return (int) longValue;
            }
            return longValue;
        }
    } catch (NumberFormatException e) {
        return null;
    }
}

From source file:com.ms.commons.test.math.expression.impl.DateOperatorMathExpression.java

public Object evaluate(Object param) {
    Object leftValue = left.evaluate(param);
    Object rightValue = right.evaluate(param);
    if ((leftValue instanceof Date) && (rightValue instanceof Double)) {
        long rv = (long) (DateUtils.MILLIS_PER_DAY * ((Double) rightValue).doubleValue());
        Date lv = (Date) leftValue;
        switch (operator) {
        case '+':
            return new Date(lv.getTime() + rv);
        case '-':
            return new Date(lv.getTime() - rv);
        default://from   www  .  j  av  a 2  s.  c om
            throw new RuntimeException("Unsupported operator between Date and Double: " + operator);
        }
    } else if ((leftValue instanceof Double) && (rightValue instanceof Double)) {
        double l = ((Double) leftValue).doubleValue();
        double r = ((Double) rightValue).doubleValue();
        switch (operator) {
        case '+':
            return Double.valueOf(l + r);
        case '-':
            return Double.valueOf(l - r);
        case '*':
            return Double.valueOf(l * r);
        case '/':
            return Double.valueOf(l / r);
        default:
            throw new RuntimeException("Unknow operator: " + operator);
        }
    } else {
        throw new RuntimeException("Error type of: " + leftValue.getClass() + " and " + rightValue.getClass());
    }
}

From source file:org.hawkular.alerts.api.model.condition.CompareConditionEval.java

public CompareConditionEval(CompareCondition condition, Data data1, Data data2) {
    super(Type.COMPARE, condition.match(Double.valueOf(data1.getValue()), Double.valueOf(data2.getValue())),
            ((data1.getTimestamp() > data1.getTimestamp()) ? data1.getTimestamp() : data2.getTimestamp()),
            data1.getContext());/*from w  w  w.  j  a v  a 2s  .co  m*/
    this.condition = condition;
    this.value1 = Double.valueOf(data1.getValue());
    this.value2 = Double.valueOf(data2.getValue());
    this.context2 = data2.getContext();
}

From source file:com.ocs.dynamo.importer.impl.BaseTextImporter.java

/**
 * Reads a numeric value form a unit (i.e. a single string or a single cell)
 * //from  w  w w .j  ava 2s.com
 * @param unit
 * @return
 */
protected Double getNumericValue(String unit) {
    String value = unit;
    if (StringUtils.isEmpty(value)) {
        return null;
    }
    try {
        return Double.valueOf(value);
    } catch (NumberFormatException ex) {
        throw new OCSImportException(value + " cannot be converted to a number");
    }
}

From source file:tr.gov.ptt.gr1tahsilatuyg.bean.TahsilatChartBean.java

@PostConstruct
public void doldurChart() {

    chartListe = tahsilatBorcService.chartVerisiGetir();

    for (Object[] chartElement : chartListe) {

        pieChartModel.set(String.valueOf(chartElement[0]), Double.valueOf(chartElement[1].toString()));

    }/*from  w  ww.  j av  a  2s . c o  m*/

}

From source file:com.google.walkaround.util.server.flags.JsonFlags.java

@VisibleForTesting
@SuppressWarnings("unchecked")
static Object parseOneFlag(FlagDeclaration decl, JSONObject json) throws FlagFormatException {
    String key = decl.getName();//from ww  w  . j  ava 2s .  c o m
    Class<?> type = decl.getType();
    try {
        if (!json.has(key)) {
            throw new FlagFormatException("Missing flag: " + key);
        }
        // Explicit check, otherwise null would be interpreted as "null" (the
        // string) for string and enum values.
        if (json.isNull(key)) {
            throw new FlagFormatException("Null value for key " + key);
        }

        if (type == String.class) {
            return json.getString(key);
        } else if (type == Boolean.class) {
            return Boolean.valueOf(json.getBoolean(key));
        } else if (type == Integer.class) {
            int val = json.getInt(key);
            if (val != json.getDouble(key)) {
                throw new FlagFormatException(
                        "Loss of precision for type int, key=" + key + ", value=" + json.getDouble(key));
            }
            return Integer.valueOf(val);
        } else if (type == Double.class) {
            return Double.valueOf(json.getDouble(key));
        } else if (type.isEnum()) {
            // TODO(ohler): Avoid unchecked warning here, the rest of the method should be clean.
            return parseEnumValue(type.asSubclass(Enum.class), key, json.getString(key).toUpperCase());
        } else {
            throw new IllegalArgumentException("Unknown flag type " + type.getName());
        }
    } catch (JSONException e) {
        throw new FlagFormatException(
                "Invalid flag JSON for key " + key + " (possibly a bad type); map=" + json, e);
    }
}

From source file:coding.cowboys.util.ResortWrapper.java

public Double getTotalPrice() {
    if (!NumberUtils.isNumber(totalPrice)) {
        System.out.println("We had a problem here need to log it: " + toString());
        return 100000000d;
    }/*ww  w.jav a 2  s  . c  o m*/
    return Double.valueOf(totalPrice);
}

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

/**
 * @see com.ottogroup.bi.streaming.operator.json.aggregate.functions.JsonContentAggregateFunction#min(java.io.Serializable, java.io.Serializable)
 *//*from  w  w w .  j a  v a2  s .  c o m*/
public Double min(Double oldMin, Double value) throws Exception {
    if (oldMin == null && value == null)
        return null;
    if (oldMin != null && value == null)
        return oldMin;
    if (oldMin == null && value != null)
        return Double.valueOf(value.doubleValue());
    if (oldMin.doubleValue() <= value.doubleValue())
        return oldMin;
    return Double.valueOf(value.doubleValue());
}

From source file:tibano.entity.ParkingTransactionRepositoryTest.java

@Test
public void findOpenTransactionByAreaAndLicensePlate() {
    // when there is a closed TX
    Car car = carRepository.save(new Car(LIC_PLATE + "1", user));
    ParkingTransaction pt = new ParkingTransaction(area, car);
    pt.end(new PaymentInfo(null, Double.valueOf(0), Duration.ZERO, Integer.valueOf(0)));
    pt = target.save(pt);//from w ww  .j a v a2s  .co  m
    // and an open TX
    pt = new ParkingTransaction(area, car);
    pt = target.save(pt);
    // then I get only the open TX
    pt = target.findOpenTransactionByAreaAndLicensePlate(pt.getArea().getId(), car.getLicensePlate());
}

From source file:net.sourceforge.fenixedu.domain.student.curriculum.CurriculumEntry.java

@Override
public BigDecimal getWeigthTimesGrade() {
    final String grade = getGradeValue();
    return StringUtils.isNumeric(grade)
            ? getWeigthForCurriculum().multiply(BigDecimal.valueOf(Double.valueOf(grade)))
            : null;/*from   w w w  .  j  av a2s  .  c  o m*/
}