Sharkysoft home

lava.array
Class ArrayShifter

java.lang.Object
  |
  +--lava.array.ArrayShifter

public class ArrayShifter
extends java.lang.Object

Shifts and rotates arrays.

Details: ArrayShifter is a collection of functions for shifting and rotating arrays.

Depending on the function name, the array is either manipulated in place, or the array is copied and then manipulated, leaving the original unmodified. In all cases, the manipulated result is returned.

Negative amounts for rotating and shifting indicate shifting towards the beginning (zero element) of the array, and positive values shift towards the end. Shifting by an amount greater than the length of the array produces an array filled with default values. Rotating by an amount greater than the length of the array produces the result you would expect to get if the array were repeatedly rotated by one element that many times.

Functions in this class are not thread-safe. If the input array is modified by another thread while it is being copied, shifted, or rotated, the results may be unpredictable. Users should develop their own thread-safety protocol for arrays that may be affected in this manner.

Since:
1998.10.31
Version:
1998.11.18

Constructor Summary
ArrayShifter()
           
 
Method Summary
static boolean[] rotateCopy(boolean[] ar, int amt)
          Rotates an array of booleans.
static byte[] rotateCopy(byte[] ar, int amt)
          Rotates an array of bytes.
static char[] rotateCopy(char[] ar, int amt)
          Rotates an array of chars.
static double[] rotateCopy(double[] ar, int amt)
          Rotates an array of doubles.
static float[] rotateCopy(float[] ar, int amt)
          Rotates an array of floats.
static int[] rotateCopy(int[] ar, int amt)
          Rotates an array of ints.
static long[] rotateCopy(long[] ar, int amt)
          Rotates an array of longs.
static java.lang.Object[] rotateCopy(java.lang.Object[] ar, int amt)
          Rotates an array of Objects.
static short[] rotateCopy(short[] ar, int amt)
          Rotates an array of shorts.
static boolean[] shiftCopy(boolean[] ar, int amt)
          Shifts an array of booleans.
static byte[] shiftCopy(byte[] ar, int amt)
          Shifts an array of bytes.
static char[] shiftCopy(char[] ar, int amt)
          Shifts an array of chars.
static double[] shiftCopy(double[] ar, int amt)
          Shifts an array of doubles.
static float[] shiftCopy(float[] ar, int amt)
          Shifts an array of floats.
static int[] shiftCopy(int[] ar, int amt)
          Shifts an array of ints.
static long[] shiftCopy(long[] ar, int amt)
          Shifts an array of longs.
static java.lang.Object[] shiftCopy(java.lang.Object[] ar, int amt)
          Shifts an array of Objects.
static short[] shiftCopy(short[] ar, int amt)
          Shifts an array of shorts.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayShifter

public ArrayShifter()
Method Detail

rotateCopy

public static final double[] rotateCopy(double[] ar,
                                        int amt)
Rotates an array of doubles.
Parameters:
ar - the array
amt - amount of rotation
Returns:
the rotated array
Since:
1988.10.31

rotateCopy

public static final float[] rotateCopy(float[] ar,
                                       int amt)
Rotates an array of floats.
Parameters:
ar - the array
amt - amount of rotation
Returns:
the rotated array
Since:
1988.10.31

rotateCopy

public static final long[] rotateCopy(long[] ar,
                                      int amt)
Rotates an array of longs.
Parameters:
ar - the array
amt - amount of rotation
Returns:
the rotated array
Since:
1988.10.31

rotateCopy

public static final int[] rotateCopy(int[] ar,
                                     int amt)
Rotates an array of ints.
Parameters:
ar - the array
amt - amount of rotation
Returns:
the rotated array
Since:
1988.10.31

rotateCopy

public static final short[] rotateCopy(short[] ar,
                                       int amt)
Rotates an array of shorts.
Parameters:
ar - the array
amt - amount of rotation
Returns:
the rotated array
Since:
1988.10.31

rotateCopy

public static final byte[] rotateCopy(byte[] ar,
                                      int amt)
Rotates an array of bytes.
Parameters:
ar - the array
amt - amount of rotation
Returns:
the rotated array
Since:
1988.10.31

rotateCopy

public static final char[] rotateCopy(char[] ar,
                                      int amt)
Rotates an array of chars.
Parameters:
ar - the array
amt - amount of rotation
Returns:
the rotated array
Since:
1988.10.31

rotateCopy

public static final boolean[] rotateCopy(boolean[] ar,
                                         int amt)
Rotates an array of booleans.
Parameters:
ar - the array
amt - amount of rotation
Returns:
the rotated array
Since:
1988.10.31

rotateCopy

public static final java.lang.Object[] rotateCopy(java.lang.Object[] ar,
                                                  int amt)
Rotates an array of Objects.

Details: shiftCopy uses Java reflection to create a new array of the same type and length as the input, performs the rotate-copy, and returns the new array. The result should probably be type-casted into the desired array type.

Parameters:
ar - the array
amt - amount of rotation
Returns:
the rotated array
Since:
1988.10.31

shiftCopy

public static final java.lang.Object[] shiftCopy(java.lang.Object[] ar,
                                                 int amt)
Shifts an array of Objects.

Details: shiftCopy uses Java reflection to create a new array of the same type and length as the input, performs the shift-copy, and returns the new array. The result should probably be type-casted into the desired array type.

Parameters:
ar - the array
amt - amount of shift
Returns:
the shifted array
Since:
1988.10.31

shiftCopy

public static final double[] shiftCopy(double[] ar,
                                       int amt)
Shifts an array of doubles.
Parameters:
ar - the array
amt - amount of shift
Returns:
the shifted array
Since:
1988.10.31

shiftCopy

public static final float[] shiftCopy(float[] ar,
                                      int amt)
Shifts an array of floats.
Parameters:
ar - the array
amt - amount of shift
Returns:
the shifted array
Since:
1988.10.31

shiftCopy

public static final long[] shiftCopy(long[] ar,
                                     int amt)
Shifts an array of longs.
Parameters:
ar - the array
amt - amount of shift
Returns:
the shifted array
Since:
1988.10.31

shiftCopy

public static final int[] shiftCopy(int[] ar,
                                    int amt)
Shifts an array of ints.
Parameters:
ar - the array
amt - amount of shift
Returns:
the shifted array
Since:
1988.10.31

shiftCopy

public static final short[] shiftCopy(short[] ar,
                                      int amt)
Shifts an array of shorts.
Parameters:
ar - the array
amt - amount of shift
Returns:
the shifted array
Since:
1988.10.31

shiftCopy

public static final char[] shiftCopy(char[] ar,
                                     int amt)
Shifts an array of chars.
Parameters:
ar - the array
amt - amount of shift
Returns:
the shifted array
Since:
1988.10.31

shiftCopy

public static final byte[] shiftCopy(byte[] ar,
                                     int amt)
Shifts an array of bytes.
Parameters:
ar - the array
amt - amount of shift
Returns:
the shifted array
Since:
1988.10.31

shiftCopy

public static final boolean[] shiftCopy(boolean[] ar,
                                        int amt)
Shifts an array of booleans.
Parameters:
ar - the array
amt - amount of shift
Returns:
the shifted array
Since:
1988.10.31

Sharkysoft home