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:org.sonar.api.measures.Measure.java

private static boolean isZeroVariation(Double... variations) {
    for (Double variation : variations) {
        if (!((variation == null) || NumberUtils.compare(variation.doubleValue(), 0.0) == 0)) {
            return false;
        }//  www.j  av a2 s  .c  om
    }
    return true;
}

From source file:org.dbmfs.DbmfsUtil.java

public static Object deserializeType(Double value, String javaTypeName) {
    if (javaTypeName.equals("java.lang.Double")) {
        return value;
    }/*from   www. ja  v  a2 s .  c  o m*/

    if (javaTypeName.equals("java.lang.Float")) {
        return value.floatValue();
    }

    if (javaTypeName.equals("java.math.BigDecimal")) {
        return new BigDecimal(value.doubleValue());
    }
    return value;
}

From source file:fr.landel.utils.commons.ObjectUtils.java

/**
 * Get the primitive value of an {@link Double}. If {@code value} is not
 * {@code null}, returns the primitive value of {@code value} otherwise returns
 * {@code defaultValue}//w w  w .j  a  v  a 2  s .  com
 * 
 * <pre>
 * Double value = new Double(1d);
 * double value1 = ObjectUtils.toPrimitive(value, 0); // =&gt; value1 = 1d
 * double value2 = ObjectUtils.toPrimitive((Double) null, 0); // =&gt; value2 = 0d
 * </pre>
 * 
 * @param value
 *            the {@link Double} value
 * @param defaultValue
 *            the default value
 * @return a primitive double
 */
public static double toPrimitive(final Double value, final double defaultValue) {
    if (value == null) {
        return defaultValue;
    } else {
        return value.doubleValue();
    }
}

From source file:ispyb.common.util.upload.UploadShipmentUtils.java

/**
 * Converts from Excel Cell contents to a double
 * //from   ww w  . ja  va2  s .  c o  m
 * @param cell
 *            The Cell to convert
 * @return The double value contained within the Cell or 0.0 if the Cell is not the correct type or is undefined
 */
public static double cellToDouble(HSSFCell cell) {
    Double retVal = new Double(0.0);
    if (cell == null) {
        return retVal.doubleValue();
    }
    if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
        retVal = new Double(cell.getNumericCellValue());
    }
    return retVal.doubleValue();
}

From source file:de.tud.kom.p2psim.impl.util.stat.distributions.LimitedNormalDistribution.java

/**
 * Returns a random value that is distributed as a Normal Distribution with
 * an upper and lower limit.//w  w w. j a va2  s. c om
 * 
 * @param _mu
 *            average
 * @param _sigma
 *            standard deviation
 * @param _min
 *            lower limit, set to "null", if no limit
 * @param _max
 *            upper limit, set to "null", if no limit
 * @return as double
 */
public static double returnValue(double _mu, double _sigma, Double _min, Double _max) {
    int llimitType;
    double lmax;
    double lmin;
    double lpmax = 1;
    double lpmin = 0;
    double lpfactor;

    NormalDistributionImpl llimitedNormal = new NormalDistributionImpl(_mu, _sigma);
    if (_min == null) {
        if (_max == null) {
            llimitType = LIMIT_NORMAL_DIST_NONE;
        } else {
            // only max is limted
            llimitType = LIMIT_NORMAL_DIST_MAX;
            lmax = _max.doubleValue();
            try {
                lpmax = llimitedNormal.cumulativeProbability(lmax);
            } catch (MathException e) {
                e.printStackTrace();
            }
        }
    } else {
        if (_max == null) {
            // only min is limited.
            llimitType = LIMIT_NORMAL_DIST_MIN;
            lmin = _min.doubleValue();
            try {
                lpmin = llimitedNormal.cumulativeProbability(lmin);
            } catch (MathException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } else {
            // both sides limited.
            llimitType = LIMIT_NORMAL_DIST_BOTH;

            // make sure min is really smaller than max.
            if (_max.doubleValue() > _min.doubleValue()) {
                lmin = _min.doubleValue();
                lmax = _max.doubleValue();
            } else {
                lmax = _min.doubleValue();
                lmin = _max.doubleValue();
            }

            // get min and max probabilites that are possible
            try {
                lpmin = llimitedNormal.cumulativeProbability(lmin);
                lpmax = llimitedNormal.cumulativeProbability(lmax);

                lpfactor = lpmax - lpmin;

            } catch (MathException e) {
                e.printStackTrace();
            }
        }
    }
    lpfactor = lpmax - lpmin;

    double lrandom = lpmin + Simulator.getRandom().nextDouble() * lpfactor;
    double lresult;

    try {
        lresult = llimitedNormal.inverseCumulativeProbability(lrandom);
    } catch (MathException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        lresult = 0;
    }

    return lresult;

}

From source file:ca.sfu.federation.model.Expression.java

/**
 * Determines the type of the left and right hand side objects, converts
 * them to an operable type, performs the add calculation then returns the
 * result object.// w  w w  .ja  v  a 2 s  . co m
 * @param lhs Left hand operand.
 * @param rhs Right hand operand.
 * @return Sum of left and right hand operands.
 * TODO: throw an exception if the add operation can not be performed
 * TODO: need to consider when objects are of different types, then convert them to a common type
 */
private static Object add(Object lhs, Object rhs) {
    // initialize
    Object result = null;
    Double dblVal = new Double(0.0);
    Integer intVal = new Integer(0);
    // determine parameter type, do calculation based on object type
    if (lhs.getClass().isInstance(dblVal) && rhs.getClass().isInstance(dblVal)) {
        // convert values to double
        Double _lhs = (Double) lhs;
        Double _rhs = (Double) rhs;
        result = add(_lhs.doubleValue(), _rhs.doubleValue());
    } else if (lhs.getClass().isInstance(intVal) && rhs.getClass().isInstance(intVal)) {
        // convert values to int
        Integer _lhs = (Integer) lhs;
        Integer _rhs = (Integer) rhs;
        result = add(_lhs.intValue(), _rhs.intValue());
    }
    // return result
    return result;
}

From source file:msi.gaml.operators.Maths.java

public static Double opTruncate(final Double x, final Integer precision) {
    double x1 = x.doubleValue();
    int precision1 = precision.intValue();
    double fract;
    double whole;
    double mult;/*ww  w.  jav a2s .  co m*/
    if (x1 > 0) {
        whole = floor(x1);
        mult = pow(10.0, precision1);
        fract = floor((x1 - whole) * mult) / mult;
    } else {
        whole = ceil(x1);
        mult = pow(10, precision1);
        fract = ceil((x1 - whole) * mult) / mult;
    }
    return whole + fract;
}

From source file:ml.shifu.shifu.core.Normalizer.java

/**
 * Parse raw value based on ColumnConfig.
 * //from   www . ja  v a 2s . co m
 * @param config
 *            ColumnConfig info
 * @param raw
 *            input column value
 * @param categoryMissingNormType
 *            missing categorical value norm type
 * @return parsed raw value. For categorical type, return BinPosRate. For numerical type, return
 *         corresponding double value. For missing data, return default value using
 *         {@link Normalizer#defaultMissingValue}.
 */
private static double parseRawValue(ColumnConfig config, Object raw,
        CategoryMissingNormType categoryMissingNormType) {
    if (categoryMissingNormType == null) {
        categoryMissingNormType = CategoryMissingNormType.POSRATE;
    }
    double value = 0.0;
    if (raw == null || StringUtils.isBlank(raw.toString())) {
        log.debug("Not decimal format but null, using default!");
        if (config.isCategorical()) {
            value = fillDefaultValue(config, categoryMissingNormType);
        } else {
            value = defaultMissingValue(config);
        }
        return value;
    }

    if (config.isCategorical()) {
        // for categorical variable, no need convert to double but double should be in treated as String in
        // categorical variables
        int index = BinUtils.getBinNum(config, raw);
        if (index == -1) {
            value = fillDefaultValue(config, categoryMissingNormType);
        } else {
            Double binPosRate = config.getBinPosRate().get(index);
            if (binPosRate != null) {
                value = binPosRate.doubleValue();
            } else {
                value = fillDefaultValue(config, categoryMissingNormType);
            }
        }
    } else {
        // for numerical value, if double or int, no need parse again.
        if (raw instanceof Double) {
            value = (Double) raw;
        } else if (raw instanceof Integer) {
            value = ((Integer) raw).doubleValue();
        } else if (raw instanceof Float) {
            value = ((Float) raw).doubleValue();
        } else {
            try {
                // if raw is NaN, it won't throw Exception. The value will be Double.NaN
                value = Double.parseDouble(raw.toString());
            } catch (Exception e) {
                log.debug("Not decimal format " + raw + ", using default!");
                value = defaultMissingValue(config);
            }
        }
        if (Double.isInfinite(value) || Double.isNaN(value)) {
            // if the value is Infinite or NaN, treat it as missing value
            // should treat Infinite as missing value?
            value = defaultMissingValue(config);
        }
    }

    return value;
}

From source file:org.kalypso.ogc.sensor.timeseries.TimeseriesUtils.java

/**
 * Return the value of the alarmLevel in regard to the given axisType. The alarm-levels are stored according to the
 * W-axis. If you want the value according to the Q-axis you should call this function with axisType = Q
 *
 * @param axisType/*from w  ww.  ja v  a  2 s. co  m*/
 *          the type of the axis for which to convert the alarm-level
 * @throws WQException
 */
public static Double convertAlarmLevel(final IObservation obs, final ITupleModel model, final Integer index,
        final String axisType, final Double alarmLevel) throws SensorException, WQException {
    if (axisType.equals(ITimeseriesConstants.TYPE_WATERLEVEL))
        return alarmLevel;

    final IWQConverter converter = WQFactory.createWQConverter(obs);

    if (axisType.equals(ITimeseriesConstants.TYPE_RUNOFF) || axisType.equals(ITimeseriesConstants.TYPE_VOLUME))
        return new Double(converter.computeQ(model, index, alarmLevel.doubleValue()));

    throw new WQException(Messages.getString("org.kalypso.ogc.sensor.timeseries.TimeserieUtils.22") + axisType //$NON-NLS-1$
            + Messages.getString("org.kalypso.ogc.sensor.timeseries.TimeserieUtils.23")); //$NON-NLS-1$
}

From source file:de.walware.statet.r.core.rsource.ast.RAst.java

public static Integer toJavaInt(RAstNode node) {
    while (node != null) {
        switch (node.getNodeType()) {
        case NUM_CONST:
            switch (node.getOperator(0)) {
            case NUM_NUM: {
                final Double num = parseNum(node.getText());
                if (num != null && num.doubleValue() == Math.rint(num.doubleValue())) {
                    return num.intValue();
                }/* w ww.  j  a  va 2s . co  m*/
                break;
            }
            case NUM_INT:
                return parseInt(node.getText());
            case TRUE:
                return 1;
            case FALSE:
                return 0;
            default:
                break;
            }
            return null;
        case F_CALL_ARG:
            node = ((FCall.Arg) node).getValueChild();
            continue;
        default:
            return null;
        }
    }
    return null;
}