@Test public void 距離なしのhowFarテスト() { int distance = Classes.howFar(JFrame.class, SwingUtilities.class); assertEquals(-1, distance); }
public static int howFar(Class<?> from, Class<?> to) { Args.checkNotNull(from); Args.checkNotNull(to); if (from == to) return 0; if (!to.isAssignableFrom(from)) return -1; int distance = 0; Class<?> hierarchyExplorer = from; while (hierarchyExplorer != null && hierarchyExplorer != to) { hierarchyExplorer = hierarchyExplorer.getSuperclass(); if (hierarchyExplorer != null) { distance++; } else { assert false; } } return distance; }
Classes { public static int howFar(Class<?> from, Class<?> to) { Args.checkNotNull(from); Args.checkNotNull(to); if (from == to) return 0; if (!to.isAssignableFrom(from)) return -1; int distance = 0; Class<?> hierarchyExplorer = from; while (hierarchyExplorer != null && hierarchyExplorer != to) { hierarchyExplorer = hierarchyExplorer.getSuperclass(); if (hierarchyExplorer != null) { distance++; } else { assert false; } } return distance; } }
Classes { public static int howFar(Class<?> from, Class<?> to) { Args.checkNotNull(from); Args.checkNotNull(to); if (from == to) return 0; if (!to.isAssignableFrom(from)) return -1; int distance = 0; Class<?> hierarchyExplorer = from; while (hierarchyExplorer != null && hierarchyExplorer != to) { hierarchyExplorer = hierarchyExplorer.getSuperclass(); if (hierarchyExplorer != null) { distance++; } else { assert false; } } return distance; } private  Classes(); }
Classes { public static int howFar(Class<?> from, Class<?> to) { Args.checkNotNull(from); Args.checkNotNull(to); if (from == to) return 0; if (!to.isAssignableFrom(from)) return -1; int distance = 0; Class<?> hierarchyExplorer = from; while (hierarchyExplorer != null && hierarchyExplorer != to) { hierarchyExplorer = hierarchyExplorer.getSuperclass(); if (hierarchyExplorer != null) { distance++; } else { assert false; } } return distance; } private  Classes(); static ClassLoader preferredClassLoader(); @SuppressWarnings("unchecked") static Class<T> forName(String className); @SuppressWarnings("unchecked") static Class<T> forName(String className, ClassLoader loader); static int howFar(Class<?> from, Class<?> to); }
Classes { public static int howFar(Class<?> from, Class<?> to) { Args.checkNotNull(from); Args.checkNotNull(to); if (from == to) return 0; if (!to.isAssignableFrom(from)) return -1; int distance = 0; Class<?> hierarchyExplorer = from; while (hierarchyExplorer != null && hierarchyExplorer != to) { hierarchyExplorer = hierarchyExplorer.getSuperclass(); if (hierarchyExplorer != null) { distance++; } else { assert false; } } return distance; } private  Classes(); static ClassLoader preferredClassLoader(); @SuppressWarnings("unchecked") static Class<T> forName(String className); @SuppressWarnings("unchecked") static Class<T> forName(String className, ClassLoader loader); static int howFar(Class<?> from, Class<?> to);  }