code: private static int classDistance(Class<?> from, Class<?> to, int current) {
          return to.isAssignableFrom(from)
              ? to.equals(from) ? current : classDistance(findAssignableAncestor(from, to), to, current + 1)
              : -1;
      }
docs: Calculates distance between from and to classes, counting from current.