/** * Convert the specified object into a Byte. * * @param value the value to convert * @return the converted value * @throws ConversionException thrown if the value cannot be converted to a byte */ public static Byte toByte(final Object value) throws ConversionException { final Number n = toNumber(value, Byte.class); if (n instanceof Byte) { return (Byte) n; } return n.byteValue(); }
/** * Convert the specified object into a Short. * * @param value the value to convert * @return the converted value * @throws ConversionException thrown if the value cannot be converted to a short */ public static Short toShort(final Object value) throws ConversionException { final Number n = toNumber(value, Short.class); if (n instanceof Short) { return (Short) n; } return n.shortValue(); }
/** * Convert the specified object into an Integer. * * @param value the value to convert * @return the converted value * @throws ConversionException thrown if the value cannot be converted to an integer */ public static Integer toInteger(final Object value) throws ConversionException { final Number n = toNumber(value, Integer.class); if (n instanceof Integer) { return (Integer) n; } return n.intValue(); }
/** * Convert the specified object into a Long. * * @param value the value to convert * @return the converted value * @throws ConversionException thrown if the value cannot be converted to a Long */ public static Long toLong(final Object value) throws ConversionException { final Number n = toNumber(value, Long.class); if (n instanceof Long) { return (Long) n; } return n.longValue(); }
/** * Convert the specified object into a BigDecimal. * * @param value the value to convert * @return the converted value * @throws ConversionException thrown if the value cannot be converted to a BigDecimal */ public static BigDecimal toBigDecimal(final Object value) throws ConversionException { final Number n = toNumber(value, BigDecimal.class); if (n instanceof BigDecimal) { return (BigDecimal) n; } return new BigDecimal(n.doubleValue()); }
/** * Convert the specified object into a Float. * * @param value the value to convert * @return the converted value * @throws ConversionException thrown if the value cannot be converted to a Float */ public static Float toFloat(final Object value) throws ConversionException { final Number n = toNumber(value, Float.class); if (n instanceof Float) { return (Float) n; } return new Float(n.floatValue()); }
/** * Convert the specified object into a Double. * * @param value the value to convert * @return the converted value * @throws ConversionException thrown if the value cannot be converted to a Double */ public static Double toDouble(final Object value) throws ConversionException { final Number n = toNumber(value, Double.class); if (n instanceof Double) { return (Double) n; } return new Double(n.doubleValue()); }
/** * Convert the specified object into a BigInteger. * * @param value the value to convert * @return the converted value * @throws ConversionException thrown if the value cannot be converted to a BigInteger */ public static BigInteger toBigInteger(final Object value) throws ConversionException { final Number n = toNumber(value, BigInteger.class); if (n instanceof BigInteger) { return (BigInteger) n; } return BigInteger.valueOf(n.longValue()); }