import java.util.ArrayList; import java.util.Collections; import java.util.List; /** * Circular shifting implementation using a list and Collections.rotate. * * @author Alexander Schaap * */ public class CircularShifter2 extends CircularShifterAbstract { /** * Another implementation of circular shifting, this time using an ArrayList * and rotating it, copying to result array one line at the time. */ public StorageInterface>> circularShifts( StorageInterface> line) { StorageInterface>> result = new StorageObservableArrayList>>(); result.add(line); List> tmp = new ArrayList>(); for (int i = 0; i < line.length(); i++) { tmp.add(line.get(i)); } for (int i = 1; i < line.length(); i++) { Collections.rotate(tmp, 1); StorageInterface> tmp2 = new StorageObservableArrayList>(); for (int j = 0; j < line.length(); j++) { tmp2.add(tmp.get(j)); } result.add(tmp2); } return result; } }