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:Main.java

@SuppressWarnings("unchecked")
public static <T> T getJsonObjectValue(JSONObject jsonObject, String key, Class<T> clazz) {
    T t = null;//from  ww w  .j  av a2s . c  om
    try {
        if (clazz == Integer.class) {
            t = (T) Integer.valueOf(jsonObject.getInt(key));
        } else if (clazz == Boolean.class) {
            t = (T) Boolean.valueOf(jsonObject.getBoolean(key));
        } else if (clazz == String.class) {
            t = (T) String.valueOf(jsonObject.getString(key));
        } else if (clazz == Double.class) {
            t = (T) Double.valueOf(jsonObject.getDouble(key));
        } else if (clazz == JSONObject.class) {
            t = (T) jsonObject.getJSONObject(key);
        } else if (clazz == JSONArray.class) {
            t = (T) jsonObject.getJSONArray(key);
        } else if (clazz == Long.class) {
            t = (T) Long.valueOf(jsonObject.getLong(key));
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return t;
}

From source file:Main.java

/**
 * @param threadToCpuRatio - for example, assuming you have 2 CPUs and setting a threadToCpuRation to 3, the result will be a pool with 6 working threads.  
 * @return an {@link ExecutorService} with defined amount of worker thread for each CPUm A {@link SynchronousQueue} and a {@link ThreadPoolExecutor.CallerRunsPolicy}
 *//* ww w .java 2  s  . c o  m*/
public static ExecutorService getTightThreadPool(double threadToCpuRatio) {
    int workingThreads = Double.valueOf(NUM_CPU * threadToCpuRatio).intValue();
    return new ThreadPoolExecutor(workingThreads, workingThreads, 60, TimeUnit.SECONDS,
            new SynchronousQueue<Runnable>(true), new ThreadPoolExecutor.CallerRunsPolicy());
}

From source file:Main.java

/**
 * //from  w  ww. j  a v a 2  s  .c o  m
 * @param array
 * @return List<Double>
 */
public static List<Double> toList(final double[] array) {
    final List<Double> list = new ArrayList<>();

    for (final double value : array) {
        list.add(Double.valueOf(value));
    }

    return list;
}

From source file:Main.java

/**
 * box the double to Double
 */
public static Double boxed(double v) {
    return Double.valueOf(v);
}

From source file:net.jakobnielsen.imagga.convert.ConverterTools.java

public static Double getDouble(String key, Object o) {
    return Double.valueOf(getString(key, o));
}

From source file:Main.java

/** Given a parent element, locate double value of a child node.
 *  @param parent Parent element/*  w  w w . j  a v a 2  s  .c o m*/
 *  @param name Name of child element
 *  @return Value of child element, or empty result
 *  @throws Exception on error parsing the number
 */
public static Optional<Double> getChildDouble(final Element parent, final String name) throws Exception {
    final Element child = getChildElement(parent, name);
    if (child == null)
        return Optional.empty();
    try {
        return Optional.of(Double.valueOf(getString(child)));
    } catch (NumberFormatException ex) {
        throw new Exception("Expected double for <" + name + ">", ex);
    }
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <T> T parse(Class<T> type, String stringValue) throws IllegalArgumentException {
    if (type.equals(String.class)) {
        return (T) stringValue;
    }/*from  www.  ja v  a 2 s. c  om*/

    if (type.equals(Boolean.class) || type.equals(boolean.class)) {
        return (T) Boolean.valueOf(stringValue);
    }
    try {
        if (type.equals(Integer.class) || type.equals(int.class)) {
            return (T) Integer.valueOf(stringValue);
        }
        if (type.equals(Long.class) || type.equals(long.class)) {
            return (T) Long.valueOf(stringValue);
        }
        if (type.equals(Short.class) || type.equals(short.class)) {
            return (T) Short.valueOf(stringValue);
        }
        if (type.equals(Byte.class) || type.equals(byte.class)) {
            return (T) Byte.valueOf(stringValue);
        }
        if (type.equals(Double.class) || type.equals(double.class)) {
            return (T) Double.valueOf(stringValue);
        }
        if (type.equals(Float.class) || type.equals(float.class)) {
            return (T) Float.valueOf(stringValue);
        }
        if (type.equals(File.class)) {
            return (T) new File(stringValue);
        }
    } catch (final NumberFormatException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
    if (type.isEnum()) {
        @SuppressWarnings("rawtypes")
        final Class enumType = type;
        return (T) Enum.valueOf(enumType, stringValue);
    }
    throw new IllegalArgumentException("Can't handle type " + type);

}

From source file:com.hackathon.gavin.currency.event.CurrencyEventCreater.java

/**
 * This method is used to create currency object from parser
 * return CurrencyEvent//w ww .j  a v a2  s.c  o m
 */
public static CurrencyEvent createCurrencyEvent() throws ParseException {

    JSONArray jSONArray = CurrencyRateParser.httpGetCall(API_URL, "prices");
    ArrayList arrayList = CurrencyRateParser.convertToArrayList(jSONArray);

    String INSTRUMENT = arrayList.get(0).toString();
    Date CURRENTTIME = parseRFC3339Date(arrayList.get(1).toString());
    double BID = Double.valueOf(arrayList.get(2).toString());
    double ASK = Double.valueOf(arrayList.get(3).toString());
    CurrencyEvent currencyEvent = new CurrencyEvent(INSTRUMENT, CURRENTTIME, BID, ASK);
    return currencyEvent;
}

From source file:Main.java

private static double FormetFileSize(long fileS, int sizeType) {
    DecimalFormat df = new DecimalFormat("#.00");
    double fileSizeLong = 0;
    switch (sizeType) {
    case SIZETYPE_B:
        fileSizeLong = Double.valueOf(df.format((double) fileS));
        break;/*from   ww w.j  ava2 s.  c om*/
    case SIZETYPE_KB:
        fileSizeLong = Double.valueOf(df.format((double) fileS / 1024));
        break;
    case SIZETYPE_MB:
        fileSizeLong = Double.valueOf(df.format((double) fileS / 1048576));
        break;
    case SIZETYPE_GB:
        fileSizeLong = Double.valueOf(df.format((double) fileS / 1073741824));
        break;
    default:
        break;
    }

    return fileSizeLong;
}

From source file:com.espertech.esper.support.util.DoubleValueAssertionUtil.java

public static boolean equals(double valueActual, double valueExpected, int precision) {
    if (precision < 1) {
        throw new IllegalArgumentException("Invalid precision value of " + precision + " supplied");
    }/*from   w ww  .  j  a v  a  2  s.  c om*/

    if ((Double.valueOf(valueActual).isNaN()) && (Double.valueOf(valueExpected).isNaN())) {
        return true;
    }
    if (((Double.valueOf(valueActual).isNaN()) && (!Double.valueOf(valueExpected).isNaN()))
            || ((!Double.valueOf(valueActual).isNaN()) && (Double.valueOf(valueExpected).isNaN()))) {
        log.debug(".equals Compare failed, " + "  valueActual=" + valueActual + "  valueExpected="
                + valueExpected);
        return false;
    }

    double factor = Math.pow(10, precision);
    double val1 = valueActual * factor;
    double val2 = valueExpected * factor;

    // Round to closest integer
    double d1 = Math.rint(val1);
    double d2 = Math.rint(val2);

    if (d1 != d2) {
        log.debug(".equals Compare failed, " + "  valueActual=" + valueActual + "  valueExpected="
                + valueExpected + "  precision=" + precision);
        return false;
    }

    return true;
}