List of usage examples for java.lang Short doubleValue
public double doubleValue()
From source file:Main.java
public static void main(String[] args) { Short shortObject = new Short("10"); double d = shortObject.doubleValue(); System.out.println("double:" + d); }
From source file:Main.java
public static void main(String[] args) { Short sObj = new Short("10"); byte b = sObj.byteValue(); System.out.println(b);//w w w .j a v a 2 s . co m short s = sObj.shortValue(); System.out.println(s); int i = sObj.intValue(); System.out.println(i); float f = sObj.floatValue(); System.out.println(f); double d = sObj.doubleValue(); System.out.println(d); long l = sObj.longValue(); System.out.println(l); }
From source file:com.github.jessemull.microflex.util.BigDecimalUtil.java
/** * Safely converts an object to a BigInteger. Loss of precision may occur. Throws * an arithmetic exception upon overflow. * @param Object object to parse// ww w.j a va 2 s .c o m * @return parsed object * @throws ArithmeticException on overflow */ public static BigDecimal toBigDecimal(Object obj) { /* Switch on class and convert to BigDecimal */ String type = obj.getClass().getSimpleName(); BigDecimal parsed; switch (type) { case "Byte": Byte by = (Byte) obj; parsed = new BigDecimal(by.doubleValue()); break; case "Short": Short sh = (Short) obj; parsed = new BigDecimal(sh.doubleValue()); break; case "Integer": Integer in = (Integer) obj; parsed = new BigDecimal(in.doubleValue()); break; case "Long": Long lo = (Long) obj; parsed = new BigDecimal(lo.doubleValue()); break; case "Float": Float fl = (Float) obj; parsed = new BigDecimal(fl.doubleValue()); break; case "BigInteger": parsed = new BigDecimal(((BigInteger) obj)); break; case "BigDecimal": parsed = (BigDecimal) obj; break; case "Double": Double db = (Double) obj; parsed = new BigDecimal(db); break; default: throw new IllegalArgumentException( "Invalid type: " + type + "\nData values " + "must extend the abstract Number class."); } return parsed; }
From source file:com.github.jessemull.microflex.util.BigDecimalUtil.java
/** * Safely converts a number to a BigInteger. Loss of precision may occur. Throws * an arithmetic exception upon overflow. * @param Number object to parse//from w w w .j av a 2 s . co m * @return parsed object * @throws ArithmeticException on overflow */ public static BigDecimal toBigDecimal(Number number) { /* Switch on class and convert to BigDecimal */ String type = number.getClass().getSimpleName(); BigDecimal parsed; switch (type) { case "Byte": Byte by = (Byte) number; parsed = new BigDecimal(by.doubleValue()); break; case "Short": Short sh = (Short) number; parsed = new BigDecimal(sh.doubleValue()); break; case "Integer": Integer in = (Integer) number; parsed = new BigDecimal(in.doubleValue()); break; case "Long": Long lo = (Long) number; parsed = new BigDecimal(lo.doubleValue()); break; case "Float": Float fl = (Float) number; parsed = new BigDecimal(fl.doubleValue()); break; case "BigInteger": parsed = new BigDecimal(((BigInteger) number)); break; case "BigDecimal": parsed = (BigDecimal) number; break; case "Double": Double db = (Double) number; parsed = new BigDecimal(db); break; default: throw new IllegalArgumentException( "Invalid type: " + type + "\nData values " + "must extend the abstract Number class."); } return parsed; }
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 w w . j a v a2s . c om*/ * @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.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/*from ww w .j av a2 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:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJDoubleEditor.java
public boolean isEditValid() { final String S_ProcName = "isEditValid"; if (!hasValue()) { setValue(null);/*from w w w . ja v a 2 s . com*/ return (true); } boolean retval = super.isEditValid(); if (retval) { try { commitEdit(); } catch (ParseException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Field is not valid - " + e.getMessage(), e); } Object obj = getValue(); if (obj == null) { retval = false; } else if (obj instanceof Float) { Float f = (Float) obj; Double v = new Double(f.doubleValue()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { retval = false; } } else if (obj instanceof Double) { Double v = (Double) obj; if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { retval = false; } } else if (obj instanceof Short) { Short s = (Short) obj; Double v = new Double(s.doubleValue()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { retval = false; } } else if (obj instanceof Integer) { Integer i = (Integer) obj; Double v = new Double(i.doubleValue()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { retval = false; } } else if (obj instanceof Long) { Long l = (Long) obj; Double v = new Double(l.doubleValue()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { retval = false; } } else if (obj instanceof BigDecimal) { BigDecimal b = (BigDecimal) obj; Double v = new Double(b.toString()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { retval = false; } } else if (obj instanceof Number) { Number n = (Number) obj; Double v = new Double(n.toString()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { retval = false; } } else { throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "EditedValue", obj, "Short, Integer, Long, BigDecimal, Float, Double or Number"); } } return (retval); }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJDoubleEditor.java
public Double getDoubleValue() { final String S_ProcName = "getDoubleValue"; Double retval;/* w w w . ja v a 2 s . co m*/ String text = getText(); if ((text == null) || (text.length() <= 0)) { retval = null; } else { if (!isEditValid()) { throw CFLib.getDefaultExceptionFactory().newInvalidArgumentException(getClass(), S_ProcName, "Field is not valid"); } try { commitEdit(); } catch (ParseException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Field is not valid - " + e.getMessage(), e); } Object obj = getValue(); if (obj == null) { retval = null; } else if (obj instanceof Float) { Float f = (Float) obj; Double v = new Double(f.doubleValue()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, minValue, maxValue); } retval = v; } else if (obj instanceof Double) { Double v = (Double) obj; if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, minValue, maxValue); } retval = v; } else if (obj instanceof Short) { Short s = (Short) obj; Double v = new Double(s.doubleValue()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, minValue, maxValue); } retval = v; } else if (obj instanceof Integer) { Integer i = (Integer) obj; Double v = new Double(i.doubleValue()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, minValue, maxValue); } retval = v; } else if (obj instanceof Long) { Long l = (Long) obj; Double v = new Double(l.doubleValue()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, minValue, maxValue); } retval = v; } else if (obj instanceof BigDecimal) { BigDecimal b = (BigDecimal) obj; Double v = new Double(b.toString()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, minValue, maxValue); } retval = v; } else if (obj instanceof Number) { Number n = (Number) obj; Double v = new Double(n.toString()); if ((v.compareTo(minValue) < 0) || (v.compareTo(maxValue) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, minValue, maxValue); } retval = v; } else { throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "EditedValue", obj, "Short, Integer, Long, BigDecimal or Number"); } } return (retval); }