public static void rotate(List<? super Object> list, int distance)
public static void rotate(List<?> list, int distance)
  public static void rotate(List<? super Object> list, int distance)  {    int size = list.size();    if (size == 0)      return;    distance %= size;    if (distance == 0)      return;    if (distance < 0)      distance += size;    if (isSequential(list))      {        reverse(list);        reverse(list.subList(0, distance));        reverse(list.subList(distance, size));      }    else      {        // Determine the least common multiple of distance and size, as there        // are (distance / LCM) loops to cycle through.        int a = size;        int lcm = distance;        int b = a % lcm;        while (b != 0)          {            a = lcm;            lcm = b;            b = a % lcm;          }        // Now, make the swaps. We must take the remainder every time through        // the inner loop so that we don't overflow i to negative values.        while (--lcm >= 0)          {            Object o = list.get(lcm);            for (int i = lcm + distance; i != lcm; i = (i + distance) % size)              o = list.set(i, o);            list.set(lcm, o);          }      }  }