public static BigDecimal bigDecimal(final Number n) { final Type t = Type.get(n.getClass()); if (t == null) { final String msg = format("Unexpected number type %s passed to bigDecimal method.", n.getClass().getCanonicalName()); _logger.warning(msg); throw new IllegalArgumentException(msg); } final BigDecimal d = (BigDecimal) convertFromTo(n, t, Type.BIG_DECIMAL); return d; }
public static BigDecimal bigDecimal(final Number n) { final Type t = Type.get(n.getClass()); if (t == null) { final String msg = format("Unexpected number type %s passed to bigDecimal method.", n.getClass().getCanonicalName()); _logger.warning(msg); throw new IllegalArgumentException(msg); } final BigDecimal d = (BigDecimal) convertFromTo(n, t, Type.BIG_DECIMAL); return d; }
public static BigInteger bigInteger(final Number n) { final Type t = Type.get(n.getClass()); if (t == null) { final String msg = format("Unexpected number type %s passed to bigInteger method.", n.getClass().getCanonicalName()); _logger.warning(msg); throw new IllegalArgumentException(msg); } if (Type.BIG_INTEGER.equals(t)) return (BigInteger) n; final BigInteger i = (BigInteger) convertFromTo(n, t, Type.BIG_INTEGER); return i; }
public static BigInteger bigInteger(final Number n) { final Type t = Type.get(n.getClass()); if (t == null) { final String msg = format("Unexpected number type %s passed to bigInteger method.", n.getClass().getCanonicalName()); _logger.warning(msg); throw new IllegalArgumentException(msg); } if (Type.BIG_INTEGER.equals(t)) return (BigInteger) n; final BigInteger i = (BigInteger) convertFromTo(n, t, Type.BIG_INTEGER); return i; }
public static Number sum(final Number a, final Number b) { if (isInteger(a) && isInteger(b)) return integerSum(a, b); final Type ta = Type.get(a.getClass()); final Type tb = Type.get(b.getClass()); if (ta == null || tb == null) { final String msg = format("Unexpected number type %s,%s passed to integerSum method.", a.getClass().getCanonicalName(), b.getClass().getCanonicalName()); _logger.warning(msg); throw new IllegalArgumentException(msg); } if (EnumSet.of(ta, tb).contains(Type.RATIONAL)) { final String msg = format("Addition for rational numbers is not supported"); _logger.warning(msg); throw new IllegalArgumentException(msg); } final BigDecimal da = (BigDecimal) convertFromTo(a, ta, Type.BIG_DECIMAL); final BigDecimal db = (BigDecimal) convertFromTo(b, tb, Type.BIG_DECIMAL); return getCanonicalObject(da.add(db)); }
public static Number sum(final Number a, final Number b) { if (isInteger(a) && isInteger(b)) return integerSum(a, b); final Type ta = Type.get(a.getClass()); final Type tb = Type.get(b.getClass()); if (ta == null || tb == null) { final String msg = format("Unexpected number type %s,%s passed to integerSum method.", a.getClass().getCanonicalName(), b.getClass().getCanonicalName()); _logger.warning(msg); throw new IllegalArgumentException(msg); } if (EnumSet.of(ta, tb).contains(Type.RATIONAL)) { final String msg = format("Addition for rational numbers is not supported"); _logger.warning(msg); throw new IllegalArgumentException(msg); } final BigDecimal da = (BigDecimal) convertFromTo(a, ta, Type.BIG_DECIMAL); final BigDecimal db = (BigDecimal) convertFromTo(b, tb, Type.BIG_DECIMAL); return getCanonicalObject(da.add(db)); }
compA = (Comparable<Number>) a; else compA = (Comparable<Number>) convertFromTo(a, ta, target); compB = convertFromTo(b, tb, target);
compA = (Comparable<Number>) a; else compA = (Comparable<Number>) convertFromTo(a, ta, target); compB = convertFromTo(b, tb, target);