Converters { public static <T, V> Converter<T, V> get(Class<T> from, Class<V> to) { if (to == Integer.class || to == int.class) { if (from == Byte.class || from == byte.class) { return (Converter<T, V>) byteToInteger; } else if (from == Short.class || from == short.class) { return (Converter<T, V>) shortToInteger; } else if (from == Long.class || from == long.class) { return (Converter<T, V>) longToInteger; } else { return null; } } else { return null; } }  static Converter<T, V> get(Class<T> from, Class<V> to); static int toInt(T value);  }
@Test public void testConversions() { assertNull(Converters.get(String.class, Boolean.class)); Converter<Byte, Integer> converter1 = Converters.get(Byte.class, Integer.class); assertNotNull(converter1); assertEquals(new Integer(3), converter1.convert(new Byte((byte) 3))); Converter<Short, Integer> converter2 = Converters.get(Short.class, Integer.class); assertNotNull(converter2); assertEquals(new Integer(3), converter2.convert(new Short((byte) 3))); Converter<Long, Integer> converter3 = Converters.get(Long.class, Integer.class); assertNotNull(converter3); assertEquals(new Integer(3), converter3.convert(new Long(3))); }