ListUtils { public static void shiftItemsWithFixedDistance(List<?> list, int[] indexArray, int offset) { Arrays.sort(indexArray); int unionOffset = computeUnionOffset(list, indexArray, offset); shiftItemsDirectly(list, indexArray, unionOffset); }  static int[] toIntArray(List<Integer> intList); static int shiftItem(List<?> list, int index, int offset); static void shiftItemToFront(List<?> list, int index); static void shiftItemToBack(List<?> list, int index); static void shiftItemsAsMuchAsPossible(List<?> list, int[] indexArray, int offset); static void shiftItemsWithFixedDistance(List<?> list, int[] indexArray, int offset);  }
@Test public void testShiftItemsWithFixedDistanceNormal() { List<String> list = Arrays.asList("A", "B", "C", "D", "E"); ListUtils.shiftItemsWithFixedDistance(list, new int[]{0, 2}, 1); Assert.assertArrayEquals(new String[]{"B", "A", "D", "C", "E"}, list.toArray()); ListUtils.shiftItemsWithFixedDistance(list, new int[]{1, 3}, -1); Assert.assertArrayEquals(new String[]{"A", "B", "C", "D", "E"}, list.toArray()); }
@Test public void testShiftItemsWithFixedDistanceOverflow() { List<String> list = Arrays.asList("A", "B", "C", "D", "E"); ListUtils.shiftItemsWithFixedDistance(list, new int[]{0, 2}, 10); Assert.assertArrayEquals(new String[]{"B", "D", "A", "E", "C"}, list.toArray()); ListUtils.shiftItemsWithFixedDistance(list, new int[]{1, 3}, -10); Assert.assertArrayEquals(new String[]{"D", "B", "E", "A", "C"}, list.toArray()); }
@Test public void testShiftItemsWithFixedDistanceOverflowCorner() { List<String> list = Arrays.asList("A", "B", "C", "D", "E"); ListUtils.shiftItemsWithFixedDistance(list, new int[]{1, 4}, 10); Assert.assertArrayEquals(new String[]{"A", "B", "C", "D", "E"}, list.toArray()); ListUtils.shiftItemsWithFixedDistance(list, new int[]{0, 2}, -10); Assert.assertArrayEquals(new String[]{"A", "B", "C", "D", "E"}, list.toArray()); }