@@ -0,0 +1,2145 @@
+/**%0A * Copyright %C2%A9 2014  Mattias Andr%C3%A9e (maandree@member.fsf.org)%0A * %0A * This program is free software: you can redistribute it and/or modify%0A * it under the terms of the GNU Affero General Public License as published by%0A * the Free Software Foundation, either version 3 of the License, or%0A * (at your option) any later version.%0A * %0A * This program is distributed in the hope that it will be useful,%0A * but WITHOUT ANY WARRANTY; without even the implied warranty of%0A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the%0A * GNU Affero General Public License for more details.%0A * %0A * You should have received a copy of the GNU Affero General Public License%0A * along with this program.  If not, see %3Chttp://www.gnu.org/licenses/%3E.%0A */%0Apackage algorithms.arrays;%0A%0Aimport java.util.*;%0A%0A%0A/**%0A * Class for rotating arrays%0A */%0Apublic class Rotate%0A%7B%0A    /*%0A     *  There are many thing you can change in this class to adapt it, for example,%0A     *  if you want in-place rotation, which probabily is a bit slower (even though%0A     *  it is less na%C3%AFve), you can reverse the array, split it at the index 'steps',%0A     *  and reverse those partitions and the concatinate back again, of cause, you%0A     *  would only reverse parts of the array, not split and concatinate it.%0A     *  You could also reverse the array while rotating it, either reverse the%0A     *  input or the output.%0A     */%0A    %0A    %0A%C2%A3%3Cfor T in boolean char byte short int long float double T; do%0A  P= O=%22$T%22 cast=%0A%C2%A3%3E%5B $T = T %5D && P=%22%3CT%3E %22 O=Object cast=%22(T%5B%5D)%22%0A    /**%0A     * Rotates an array%0A     *%0A     * @param   items  The array to rotate%0A     * @param   steps  The number of steps to higher index to rotate elements%0A     * @return         The array rotated%0A     */%0A%C2%A3%3E%5B $T = T %5D &&%0A    @SuppressWarnings(%22unchecked%22)%0A    public static %C2%A3%7BP%7D%C2%A3%7BT%7D%5B%5D rotateClone(%C2%A3%7BT%7D%5B%5D items, int steps)%0A    %7B%0A%09%C2%A3%7BO%7D%5B%5D rc = new %C2%A3%7BO%7D%5Bitems.length%5D;%0A%09%0A%09int n = items.length;%0A%09if ((n & -n) == n) /* power of 2 */%0A%09    for (int i = 0, m = n - 1; i %3C n; i++)%0A%09%09rc%5B(steps + i) & m%5D = items%5Bi%5D;%0A%09else%0A%09    for (int i = 0; i %3C n; i++)%0A%09%09rc%5B(steps + i) %25 n%5D = items%5Bi%5D;%0A%09%0A%09return %C2%A3%7Bcast%7Drc;%0A    %7D%0A%C2%A3%3Edone%0A%7D%0A%0A

add rotate