@Test public void testPlus() { Assert.assertEquals(Integer.class, ALU.plus(b, b).getClass()); Assert.assertEquals(Integer.class, ALU.plus(b, s).getClass()); Assert.assertEquals(Integer.class, ALU.plus(b, i).getClass()); Assert.assertEquals(Long.class, ALU.plus(b, l).getClass()); Assert.assertEquals(Float.class, ALU.plus(b, f).getClass()); Assert.assertEquals(Double.class, ALU.plus(b, d).getClass()); }
public static Object plus(Object o1, Object o2) throws IllegalStateException { Class<?> c1 = o1.getClass(); Class<?> c2 = o2.getClass(); if (c1 == String.class || c2 == String.class) { return String.valueOf(o1).concat(String.valueOf(o2)); } if (Number.class.isAssignableFrom(c1) && Number.class.isAssignableFrom(c2)) { Number n1 = (Number) o1; Number n2 = (Number) o2; switch (getNumberType(c1, c2)) { case BYTE: case SHORT: case INTEGER: return Integer.valueOf(n1.intValue() + n2.intValue()); case LONG: return Long.valueOf(n1.longValue() + n2.longValue()); case FLOAT: return Float.valueOf(n1.floatValue() + n2.floatValue()); case DOUBLE: return Double.valueOf(n1.doubleValue() + n2.doubleValue()); } } throw new IllegalStateException(Errors.format(Errors.OPERATION_BINARY_UNDEFINED, "+", Errors.typeName(o1), Errors.typeName(o2))); }
ALU { public static Object plus(Object o1, Object o2) throws IllegalStateException { Class<?> c1 = o1.getClass(); Class<?> c2 = o2.getClass(); if (c1 == String.class || c2 == String.class) { return String.valueOf(o1).concat(String.valueOf(o2)); } if (Number.class.isAssignableFrom(c1) && Number.class.isAssignableFrom(c2)) { Number n1 = (Number) o1; Number n2 = (Number) o2; switch (getNumberType(c1, c2)) { case BYTE: case SHORT: case INTEGER: return Integer.valueOf(n1.intValue() + n2.intValue()); case LONG: return Long.valueOf(n1.longValue() + n2.longValue()); case FLOAT: return Float.valueOf(n1.floatValue() + n2.floatValue()); case DOUBLE: return Double.valueOf(n1.doubleValue() + n2.doubleValue()); } } throw new IllegalStateException(Errors.format(Errors.OPERATION_BINARY_UNDEFINED, "+", Errors.typeName(o1), Errors.typeName(o2))); } }
ALU { public static Object plus(Object o1, Object o2) throws IllegalStateException { Class<?> c1 = o1.getClass(); Class<?> c2 = o2.getClass(); if (c1 == String.class || c2 == String.class) { return String.valueOf(o1).concat(String.valueOf(o2)); } if (Number.class.isAssignableFrom(c1) && Number.class.isAssignableFrom(c2)) { Number n1 = (Number) o1; Number n2 = (Number) o2; switch (getNumberType(c1, c2)) { case BYTE: case SHORT: case INTEGER: return Integer.valueOf(n1.intValue() + n2.intValue()); case LONG: return Long.valueOf(n1.longValue() + n2.longValue()); case FLOAT: return Float.valueOf(n1.floatValue() + n2.floatValue()); case DOUBLE: return Double.valueOf(n1.doubleValue() + n2.doubleValue()); } } throw new IllegalStateException(Errors.format(Errors.OPERATION_BINARY_UNDEFINED, "+", Errors.typeName(o1), Errors.typeName(o2))); }  }
ALU { public static Object plus(Object o1, Object o2) throws IllegalStateException { Class<?> c1 = o1.getClass(); Class<?> c2 = o2.getClass(); if (c1 == String.class || c2 == String.class) { return String.valueOf(o1).concat(String.valueOf(o2)); } if (Number.class.isAssignableFrom(c1) && Number.class.isAssignableFrom(c2)) { Number n1 = (Number) o1; Number n2 = (Number) o2; switch (getNumberType(c1, c2)) { case BYTE: case SHORT: case INTEGER: return Integer.valueOf(n1.intValue() + n2.intValue()); case LONG: return Long.valueOf(n1.longValue() + n2.longValue()); case FLOAT: return Float.valueOf(n1.floatValue() + n2.floatValue()); case DOUBLE: return Double.valueOf(n1.doubleValue() + n2.doubleValue()); } } throw new IllegalStateException(Errors.format(Errors.OPERATION_BINARY_UNDEFINED, "+", Errors.typeName(o1), Errors.typeName(o2))); }  static int getNumberType(Class<?> cls); static int getNumberType(Class<?> c1, Class<?> c2); static Object plus(Object o1, Object o2); static Object minus(Object o1, Object o2); static Object mul(Object o1, Object o2); static Object div(Object o1, Object o2); static Object mod(Object o1, Object o2); static Object positive(Object o); static Object negative(Object o); static Object bitAnd(Object o1, Object o2); static Object bitOr(Object o1, Object o2); static Object bitXor(Object o1, Object o2); static Object bitNot(Object o); static Object shl(Object o1, Object o2); static Object shr(Object o1, Object o2); static Object ushr(Object o1, Object o2); static Boolean equals(Object o1, Object o2); @SuppressWarnings("unchecked") static Object gt(Object o1, Object o2); @SuppressWarnings("unchecked") static Object ge(Object o1, Object o2); @SuppressWarnings("unchecked") static Object lt(Object o1, Object o2); @SuppressWarnings("unchecked") static Object le(Object o1, Object o2); static boolean isTrue(Object o); }
ALU { public static Object plus(Object o1, Object o2) throws IllegalStateException { Class<?> c1 = o1.getClass(); Class<?> c2 = o2.getClass(); if (c1 == String.class || c2 == String.class) { return String.valueOf(o1).concat(String.valueOf(o2)); } if (Number.class.isAssignableFrom(c1) && Number.class.isAssignableFrom(c2)) { Number n1 = (Number) o1; Number n2 = (Number) o2; switch (getNumberType(c1, c2)) { case BYTE: case SHORT: case INTEGER: return Integer.valueOf(n1.intValue() + n2.intValue()); case LONG: return Long.valueOf(n1.longValue() + n2.longValue()); case FLOAT: return Float.valueOf(n1.floatValue() + n2.floatValue()); case DOUBLE: return Double.valueOf(n1.doubleValue() + n2.doubleValue()); } } throw new IllegalStateException(Errors.format(Errors.OPERATION_BINARY_UNDEFINED, "+", Errors.typeName(o1), Errors.typeName(o2))); }  static int getNumberType(Class<?> cls); static int getNumberType(Class<?> c1, Class<?> c2); static Object plus(Object o1, Object o2); static Object minus(Object o1, Object o2); static Object mul(Object o1, Object o2); static Object div(Object o1, Object o2); static Object mod(Object o1, Object o2); static Object positive(Object o); static Object negative(Object o); static Object bitAnd(Object o1, Object o2); static Object bitOr(Object o1, Object o2); static Object bitXor(Object o1, Object o2); static Object bitNot(Object o); static Object shl(Object o1, Object o2); static Object shr(Object o1, Object o2); static Object ushr(Object o1, Object o2); static Boolean equals(Object o1, Object o2); @SuppressWarnings("unchecked") static Object gt(Object o1, Object o2); @SuppressWarnings("unchecked") static Object ge(Object o1, Object o2); @SuppressWarnings("unchecked") static Object lt(Object o1, Object o2); @SuppressWarnings("unchecked") static Object le(Object o1, Object o2); static boolean isTrue(Object o); static final Object VOID; static final int NaN; static final int DOUBLE; static final int FLOAT; static final int LONG; static final int INTEGER; static final int SHORT; static final int BYTE; }