Example usage for java.lang Double shortValue

List of usage examples for java.lang Double shortValue

Introduction

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

Prototype

public short shortValue() 

Source Link

Document

Returns the value of this Double as a short after a narrowing primitive conversion.

Usage

From source file:Main.java

public static void main(String[] args) {
    Double doubleObject = new Double("10.01");

    short s = doubleObject.shortValue();
    System.out.println("short:" + s);
}

From source file:Main.java

public static void main(String[] args) {
    Double dObj = new Double("10.50");
    byte b = dObj.byteValue();
    System.out.println(b);/*  w  w w.j a  v a  2 s.  c o  m*/

    short s = dObj.shortValue();
    System.out.println(s);

    int i = dObj.intValue();
    System.out.println(i);

    float f = dObj.floatValue();
    System.out.println(f);

    double d = dObj.doubleValue();
    System.out.println(d);
}

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

/**
 * Converts a list of doubles to a list of shorts.
 * @param    List<Double>    list of doubles
 * @return                   list of shorts
 *///from ww  w .ja va 2s .  c o  m
public static List<Short> toShortList(List<Double> list) {

    List<Short> shortList = new ArrayList<Short>();

    for (Double val : list) {
        if (!OverFlowUtil.shortOverflow(val)) {
            OverFlowUtil.overflowError(val);
        }
        shortList.add(val.shortValue());
    }

    return shortList;

}

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

/**
 * Convert a Double to an Object of a given class
 * @param value Double value to convert/*ww  w  . j a  v  a  2 s . c  om*/
 * @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");
}