TypeUtil { public static int computeDistance(Class<?> parent, Class<?> child) { int distance = -1; if (parent.equals(child)) { distance = 0; } if (distance == -1) { distance = computeSuperDistance(parent, child); } if (distance == -1) { distance = computeInterfaceDistance(parent, child, new HashSet<String>(), Arrays.asList(child.getInterfaces())); } if (distance != -1) { distance *= DISTANCE_FACTOR; } return distance; }  static int computeCharacterConversion(Class<?> parent, Class<?> child, List<TypeConverter> converters); static int computeDistance(Class<?> parent, Class<?> child); static int computeNumericConversion(Class<?> parent, Class<?> child, List<TypeConverter> converters); static Class<?> forName(String fqn); static Class<?> forName(String fqn, JVMView view); static Class<?> getClass(String simpleName, JVMView view); static int getCost(Class<?> parent, Class<?> child); static String getName(String name, boolean shortName); static List<String> getNames(Class<?>[] classes); static String getPackage(String name); static int getPoint(Class<?> clazz); static boolean isBoolean(Class<?> clazz); static boolean isByte(Class<?> clazz); static boolean isCharacter(Class<?> clazz); static boolean isDouble(Class<?> clazz); static boolean isFloat(Class<?> clazz); static boolean isInteger(Class<?> clazz); static boolean isLong(Class<?> clazz); static boolean isNumeric(Class<?> clazz); static boolean isShort(Class<?> clazz); static boolean isInstanceOf(Class<?> clazz, Object object); static boolean isInstanceOf(String classFQN, Object object); final static int DISTANCE_FACTOR; }
@Test public void testDistance() { assertEquals(0, TypeUtil.computeDistance(ATest.class, ATest.class)); assertEquals(100, TypeUtil.computeDistance(ATest.class, BTest.class)); assertEquals(200, TypeUtil.computeDistance(ATest.class, CTest.class)); assertEquals(300, TypeUtil.computeDistance(ATest.class, DTest.class)); assertEquals(400, TypeUtil.computeDistance(Object.class, DTest.class)); assertEquals(-1, TypeUtil.computeDistance(int.class, DTest.class)); assertEquals(-1, TypeUtil.computeDistance(String.class, DTest.class)); assertEquals(100, TypeUtil.computeDistance(I0Test.class, I1Test.class)); assertEquals(100, TypeUtil.computeDistance(I0Test.class, VTest.class)); assertEquals(200, TypeUtil.computeDistance(I0Test.class, WTest.class)); assertEquals(100, TypeUtil.computeDistance(I1Test.class, WTest.class)); assertEquals(100, TypeUtil.computeDistance(I0Test.class, XTest.class)); assertEquals(200, TypeUtil.computeDistance(I0Test.class, YTest.class)); assertEquals(300, TypeUtil.computeDistance(J0Test.class, YTest.class)); assertEquals(400, TypeUtil.computeDistance(I0Test.class, ZTest.class)); }