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.ohmage.service.UploadValidationServices.java

/**
 * Validates the provided latitude.//w  w w.  j a  v a2  s  . c  o m
 * 
 * @param latitude  The latitude to validate
 * @throws ServiceException if the latitude is null or not within the range
 * of a correct latitude (-90 < latitude < 90)
 */
public static void validateLatitude(final Double latitude) throws ServiceException {

    if (latitude == null) {
        throw new ServiceException(ErrorCode.SERVER_INVALID_LOCATION, "latitude in upload message is null");
    }

    if (latitude.doubleValue() < -90d || latitude.doubleValue() > 90d) {
        throw new ServiceException(ErrorCode.SERVER_INVALID_LOCATION,
                "latitude in upload message is invalid: " + latitude);
    }
}

From source file:org.ohmage.service.UploadValidationServices.java

/**
 * Validates the provided longitude.//from   www  . j ava2 s.com
 * 
 * @param longitude The longitude to validate
 * @throws ServiceException if the latitude is null or not within the range
 * of a correct longitude (-180 < latitude < 180)
 */
public static void validateLongitude(final Double longitude) throws ServiceException {

    if (longitude == null) {
        throw new ServiceException(ErrorCode.SERVER_INVALID_LOCATION, "longitude in upload message is null");
    }

    if (longitude.doubleValue() < -180d || longitude.doubleValue() > 180d) {
        throw new ServiceException(ErrorCode.SERVER_INVALID_LOCATION,
                "longitude in upload message is invalid: " + longitude);
    }
}

From source file:com.alibaba.jstorm.ui.UIUtils.java

public static double getDoubleValue(Double value) {
    double ret = (value != null ? value.doubleValue() : 0.0);
    return ret;//from  ww  w  . ja v  a2 s  .  c  om
}

From source file:de.openali.odysseus.chart.framework.model.data.DataRange.java

@Deprecated
public static <T> DataRange<T> create(final T min, final T max) {
    if (min instanceof Number && max instanceof Number) {
        final Double minNum = ((Number) min).doubleValue();
        final Double maxNum = ((Number) max).doubleValue();

        // Beide gleich => dataRange automatisch so anpassen, dass der Wert
        // in der Intervallmitte liegt
        if (minNum.compareTo(maxNum) == 0) {
            final double doubleValue = minNum.doubleValue();
            // falls != 0 werden einfach 10% addiert oder subtrahiert
            if (doubleValue != 0) {
                final T minExpanded = (T) new Double(doubleValue - doubleValue * 0.1);
                final T maxExpanded = (T) new Double(doubleValue + doubleValue * 0.1);
                return new DataRange<>(minExpanded, maxExpanded);
            }/*from   w  w w .ja  v  a2  s .c o m*/
            // falls == 0 wird 1 addiert oder subtrahiert
            else {
                final T min_1 = (T) new Double(doubleValue - 1);
                final T max_1 = (T) new Double(doubleValue + 1);
                return new DataRange<>(min_1, max_1);
            }
        }

        if (minNum.compareTo(maxNum) > 0)
            return new DataRange<>(max, min);
        else
            return new DataRange<>(min, max);

    } else if (min instanceof Comparable && max instanceof Comparable
            && (min.getClass().isInstance(max) || max.getClass().isInstance(min))) {
        // FIXME: this is nonsense! REMOVE
        final Comparable<Comparable<?>> minComp = (Comparable<Comparable<?>>) min;
        final Comparable<?> maxComp = (Comparable<?>) max;
        if (minComp.compareTo(maxComp) == 0) {
            // kann leider nicht automatisch angepasst werden; das muss
            // jemand anders abfangen
        }

        if (minComp.compareTo(maxComp) > 0)
            return new DataRange<>(max, min);
        else
            return new DataRange<>(min, max);

    }
    /*
     * das wre dann der ungnstigste Fall: nicht vergleichbar und nicht numerisch TODO: berlegen, ob dieser Fall
     * berhaupt zugelassen werden soll; alternativ sollte eine InvalidRangeIntervalObjectsException
     */
    else {
        return new DataRange<>(min, max);
    }
}

From source file:com.wso2telco.core.dbutils.DbUtils.java

/**
 * Format./*from w  w  w .  ja v a  2  s. c  o  m*/
 *
 * @param doubleData
 *            the double data
 * @param precision
 *            the precision
 * @param scale
 *            the scale
 * @return the string
 * @throws Exception
 *             the exception
 */
public static String format(Double doubleData, int precision, int scale) throws Exception {
    double doubData;

    doubData = doubleData.doubleValue();
    return (format(doubData, precision, scale));
}

From source file:anotadorderelacoes.model.UtilidadesPacotes.java

/**
 * Mtodo utilitrio para imprimir Doubles sem zeros excedentes
 * //w  w w . ja  v a  2 s  .c  om
 * @param d Double que se deseja imprimir
 * @return Representao em texto do Double com 17 casas decimais e sem
 *         zeros excedentes
 */
public static String doubleToString(Double d) {
    String valorString = String.format(Locale.US, "%.17f", d.doubleValue());
    while (valorString.endsWith("0") && !valorString.endsWith(".0"))
        valorString = valorString.substring(0, valorString.length() - 1);
    return valorString;
}

From source file:com.github.jessemull.microflex.util.DoubleUtil.java

/**
 * Safely converts an object to a double. Loss of precision may occur. Throws
 * an arithmetic exception upon overflow.
 * @param    Object    object to parse/*from  w ww  . j a  va2s  .  c o m*/
 * @return             parsed object
 * @throws   ArithmeticException    on overflow
 */
public static double toDouble(Object obj) {

    /* Switch on class and convert to double */

    String type = obj.getClass().getSimpleName();
    double parsed;

    switch (type) {

    case "Byte":
        Byte by = (Byte) obj;
        parsed = by.doubleValue();
        break;

    case "Short":
        Short sh = (Short) obj;
        parsed = sh.doubleValue();
        break;

    case "Integer":
        Integer in = (Integer) obj;
        parsed = in.doubleValue();
        break;

    case "Long":
        Long lo = (Long) obj;
        parsed = lo.doubleValue();
        break;

    case "Float":
        Float fl = (Float) obj;
        parsed = fl.doubleValue();
        break;

    case "BigInteger":
        BigInteger bi = (BigInteger) obj;
        if (!OverFlowUtil.doubleOverflow(bi)) {
            throw new ArithmeticException("Overflow casting " + obj + " to a double.");
        }
        parsed = bi.doubleValue();
        break;

    case "BigDecimal":
        BigDecimal bd = (BigDecimal) obj;
        if (!OverFlowUtil.doubleOverflow(bd)) {
            throw new ArithmeticException("Overflow casting " + obj + " to a double.");
        }
        parsed = bd.doubleValue();
        break;

    case "Double":
        Double db = (Double) obj;
        parsed = db.doubleValue();
        break;

    default:
        throw new IllegalArgumentException(
                "Invalid type: " + type + "\nData values " + "must extend the abstract Number class.");

    }

    return parsed;
}

From source file:com.projity.util.ClassUtils.java

/**
 * Convert a Double to an Object of a given class
 * @param value Double value to convert/*from www. j a  v a  2s. c o  m*/
 * @param clazz Class the class to convert to
 * @return new object of the given class
 * @throws IllegalArgumentException if the value is not convertible to the class
 */
public static Object doubleToObject(Double value, Class clazz) {
    if (clazz == Boolean.class)
        return new Boolean(value.doubleValue() != 0.0);
    else if (clazz == Byte.class)
        return new Byte(value.byteValue());
    else if (clazz == Short.class)
        return new Short(value.shortValue());
    else if (clazz == Integer.class)
        return new Integer(value.intValue());
    else if (clazz == Long.class)
        return new Long(value.longValue());
    else if (clazz == Float.class)
        return new Float(value.floatValue());
    else if (clazz == Double.class)
        return value;
    else if (clazz == Money.class)
        return Money.getInstance(value.doubleValue());
    else if (clazz == Duration.class)
        return Duration.getInstanceFromDouble(value);
    else if (clazz == Work.class)
        return Work.getWorkInstanceFromDouble(value);

    throw new IllegalArgumentException("Class " + clazz + " cannot be converted from a Double");
}

From source file:com.github.jessemull.microflex.util.DoubleUtil.java

/**
 * Safely converts a number to a double. Loss of precision may occur. Throws
 * an arithmetic exception upon overflow.
 * @param    Number    number to parse//ww  w  . j  av a  2  s  . c  o  m
 * @return             parsed number
 * @throws   ArithmeticException    on overflow
 */
public static double toDouble(Number number) {

    /* Switch on class and convert to double */

    String type = number.getClass().getSimpleName();
    double parsed;

    switch (type) {

    case "Byte":
        Byte by = (Byte) number;
        parsed = by.doubleValue();
        break;

    case "Short":
        Short sh = (Short) number;
        parsed = sh.doubleValue();
        break;

    case "Integer":
        Integer in = (Integer) number;
        parsed = in.doubleValue();
        break;

    case "Long":
        Long lo = (Long) number;
        parsed = lo.doubleValue();
        break;

    case "Float":
        Float fl = (Float) number;
        parsed = fl.doubleValue();
        break;

    case "BigInteger":
        BigInteger bi = (BigInteger) number;
        if (!OverFlowUtil.doubleOverflow(bi)) {
            throw new ArithmeticException("Overflow casting " + number + " to a double.");
        }
        parsed = bi.doubleValue();
        break;

    case "BigDecimal":
        BigDecimal bd = (BigDecimal) number;
        if (!OverFlowUtil.doubleOverflow(bd)) {
            throw new ArithmeticException("Overflow casting " + number + " to a double.");
        }
        parsed = bd.doubleValue();
        break;

    case "Double":
        Double db = (Double) number;
        parsed = db.doubleValue();
        break;

    default:
        throw new IllegalArgumentException(
                "Invalid type: " + type + "\nData values " + "must extend the abstract Number class.");

    }

    return parsed;
}

From source file:com.wso2telco.dbutils.DbUtils.java

/**
 * Format./* w  ww .ja va 2  s. co  m*/
 *
 * @param doubleData
 *            the double data
 * @param precision
 *            the precision
 * @param scale
 *            the scale
 * @return the string
 * @throws Exception
 *             the exception
 */
public static String format(Double doubleData, int precision, int scale) throws Exception {
    double doubData;
    String finalStr;

    doubData = doubleData.doubleValue();
    return (format(doubData, precision, scale));
}