de.jreality.util
Class ArrayUtility

java.lang.Object
  extended by de.jreality.util.ArrayUtility

public final class ArrayUtility
extends java.lang.Object

This class provides utilities for arrays as static methods.

Most operation performed on the target array can imply a change of its length. Those methods create a new array and return this instead of the original which is only returned if it has already the right length.

Author:
Markus Schmies

Field Summary
static double DOUBLE_EPS
          Default threshold for double epsilon tests is 1e-12.
static float FLOAT_EPS
          Default threshold for float epsilon tests is 1e-6.
 
Method Summary
static double[] concat(double[] target, double[] con, double[] cat)
          Retuns an array containing the contents of con and cat.
static float[] concat(float[] target, float[] con, float[] cat)
          Retuns an array containing the contents of con and cat.
static int[] concat(int[] target, int[] con, int[] cat)
          Retuns an array containing the contents of con and cat.
static double[] copy(double[] source, double[] target)
          Returns copy of source which is the target if it is not null and has the right size.
static float[] copy(float[] source, float[] target)
          Returns copy of source which is the target if it is not null and has the right size.
static int[] copy(int[] source, int[] target)
          Returns copy of source which is the target if it is not null and has the right size.
static boolean equal(double[] a, double[] b)
          Test whether arrays a and b are equal using an epsilon test.
static boolean equal(double[] a, double[] b, double eps)
          Test whether arrays a and b are equal using an epsilon test.
static boolean equal(float[] a, float[] b)
          Test whether arrays a and b are equal using an epsilon test.
static boolean equal(float[] a, float[] b, float eps)
          Test whether arrays a and b are equal using an epsilon test.
static boolean equal(int[] a, int[] b)
          Test whether arrays a and b are equal.
static void fill(double[] target, double value)
          Fills target with value.
static void fill(double[] target, int position, int length, double value)
          Fills target from postion to postion+length-1 with value.
static void fill(float[] target, float value)
          Fills target with value.
static void fill(float[] target, int position, int length, float value)
          Fills target from postion to postion+length-1 with value.
static void fill(int[] target, int value)
          Fills target with value.
static void fill(int[] target, int position, int length, int value)
          Fills target from postion to postion+length-1 with value.
static double max(double[] target)
          Returns the maximum of target.
static double max(double[] target, int position, int length)
          Returns the maximum of target from postion to postion+length-1.
static float max(float[] target)
          Returns the maximum of target.
static float max(float[] target, int position, int length)
          Returns the maximum of target from postion to postion+length-1.
static int max(int[] target)
          Returns the maximum of target.
static int max(int[] target, int position, int length)
          Returns the maximum of target from postion to postion+length-1.
static double min(double[] target)
          Returns the minimum of target.
static double min(double[] target, int position, int length)
          Returns the minimum of target from postion to postion+length-1.
static float min(float[] target)
          Returns the minimum of target.
static float min(float[] target, int position, int length)
          Returns the minimum of target from postion to postion+length-1.
static int min(int[] target)
          Returns the minimum of target/.
static int min(int[] target, int position, int length)
          Returns the minimum of target from postion to postion+length-1.
static double[] resize(double[] target, int size)
          Like size(double[],int) but copies also the contents of the target if nessecary.
static float[] resize(float[] target, int size)
          Like size(float[],int) but copies also the contents of the target if nessecary.
static int[] resize(int[] target, int size)
          Like size(int[],int) but copies also the contents of the target if nessecary.
static double[] size(double[] target, int size)
          Just returns target if its length equal size.
static float[] size(float[] target, int size)
          Just returns target if its length equals size.
static int[] size(int[] target, int size)
          Just returns target if its length equals size.
static double sum(double[] target)
          Returns the sum of target.
static double sum(double[] target, int position, int length)
          Returns the sum of target from postion to postion+length-1.
static float sum(float[] target)
          Returns the sum of target.
static float sum(float[] target, int position, int length)
          Returns the sum of target from postion to postion+length-1.
static int sum(int[] target)
          Returns the sum of target.
static int sum(int[] target, int position, int length)
          Returns the sum of target from postion to postion+length-1.
static double[] unrole(double[] target, double[] values, int numOfTimes)
          Returns an array containing numOfTimes copies of the contens of values.
static float[] unrole(float[] target, float[] values, int numOfTimes)
          Returns an array containing numOfTimes copies of the contens of values.
static int[] unrole(int[] target, int[] values, int numOfTimes)
          Returns an array containing numOfTimes copies of the contens of values.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FLOAT_EPS

public static final float FLOAT_EPS
Default threshold for float epsilon tests is 1e-6.

See Also:
Constant Field Values

DOUBLE_EPS

public static final double DOUBLE_EPS
Default threshold for double epsilon tests is 1e-12.

See Also:
Constant Field Values
Method Detail

equal

public static final boolean equal(double[] a,
                                  double[] b,
                                  double eps)
Test whether arrays a and b are equal using an epsilon test.

Parameters:
a - double array
b - double array
eps - threshold for epsilon test

equal

public static final boolean equal(double[] a,
                                  double[] b)
Test whether arrays a and b are equal using an epsilon test. DOUBLE_EPS

Parameters:
a - double array
b - double array

copy

public static final double[] copy(double[] source,
                                  double[] target)
Returns copy of source which is the target if it is not null and has the right size.


size

public static final double[] size(double[] target,
                                  int size)
Just returns target if its length equal size. Otherwise, this includes target is null, it creates an array of length size and returns this instead.


resize

public static final double[] resize(double[] target,
                                    int size)
Like size(double[],int) but copies also the contents of the target if nessecary.


unrole

public static final double[] unrole(double[] target,
                                    double[] values,
                                    int numOfTimes)
Returns an array containing numOfTimes copies of the contens of values. The method uses target if it is not null and has the right size.


concat

public static final double[] concat(double[] target,
                                    double[] con,
                                    double[] cat)
Retuns an array containing the contents of con and cat. The method uses target if it is not null and has the right size.


fill

public static final void fill(double[] target,
                              double value)
Fills target with value.


fill

public static final void fill(double[] target,
                              int position,
                              int length,
                              double value)
Fills target from postion to postion+length-1 with value.


sum

public static final double sum(double[] target)
Returns the sum of target.


sum

public static final double sum(double[] target,
                               int position,
                               int length)
Returns the sum of target from postion to postion+length-1.


min

public static final double min(double[] target)
Returns the minimum of target.


min

public static final double min(double[] target,
                               int position,
                               int length)
Returns the minimum of target from postion to postion+length-1.


max

public static final double max(double[] target)
Returns the maximum of target.


max

public static final double max(double[] target,
                               int position,
                               int length)
Returns the maximum of target from postion to postion+length-1.


equal

public static final boolean equal(float[] a,
                                  float[] b,
                                  float eps)
Test whether arrays a and b are equal using an epsilon test.

Parameters:
a - float array
b - float array
eps - threshold for epsilon test

equal

public static final boolean equal(float[] a,
                                  float[] b)
Test whether arrays a and b are equal using an epsilon test. FLOAT_EPS

Parameters:
a - float array
b - float array

copy

public static final float[] copy(float[] source,
                                 float[] target)
Returns copy of source which is the target if it is not null and has the right size.


size

public static final float[] size(float[] target,
                                 int size)
Just returns target if its length equals size. Otherwise, this includes target is null, it creates an array of length size and returns this instead.


resize

public static final float[] resize(float[] target,
                                   int size)
Like size(float[],int) but copies also the contents of the target if nessecary.


unrole

public static final float[] unrole(float[] target,
                                   float[] values,
                                   int numOfTimes)
Returns an array containing numOfTimes copies of the contens of values. The method uses target if it is not null and has the right size.


concat

public static final float[] concat(float[] target,
                                   float[] con,
                                   float[] cat)
Retuns an array containing the contents of con and cat. The method uses target if it is not null and has the right size.


fill

public static final void fill(float[] target,
                              float value)
Fills target with value.


fill

public static final void fill(float[] target,
                              int position,
                              int length,
                              float value)
Fills target from postion to postion+length-1 with value.


sum

public static final float sum(float[] target)
Returns the sum of target.


sum

public static final float sum(float[] target,
                              int position,
                              int length)
Returns the sum of target from postion to postion+length-1.


min

public static final float min(float[] target)
Returns the minimum of target.


min

public static final float min(float[] target,
                              int position,
                              int length)
Returns the minimum of target from postion to postion+length-1.


max

public static final float max(float[] target)
Returns the maximum of target.


max

public static final float max(float[] target,
                              int position,
                              int length)
Returns the maximum of target from postion to postion+length-1.


equal

public static final boolean equal(int[] a,
                                  int[] b)
Test whether arrays a and b are equal.

Parameters:
a - int array
b - int array

copy

public static final int[] copy(int[] source,
                               int[] target)
Returns copy of source which is the target if it is not null and has the right size.


size

public static final int[] size(int[] target,
                               int size)
Just returns target if its length equals size. Otherwise, this includes target is null, it creates an array of length size and returns this instead.


resize

public static final int[] resize(int[] target,
                                 int size)
Like size(int[],int) but copies also the contents of the target if nessecary.


unrole

public static final int[] unrole(int[] target,
                                 int[] values,
                                 int numOfTimes)
Returns an array containing numOfTimes copies of the contens of values. The method uses target if it is not null and has the right size.


concat

public static final int[] concat(int[] target,
                                 int[] con,
                                 int[] cat)
Retuns an array containing the contents of con and cat. The method uses target if it is not null and has the right size.


fill

public static final void fill(int[] target,
                              int value)
Fills target with value.


fill

public static final void fill(int[] target,
                              int position,
                              int length,
                              int value)
Fills target from postion to postion+length-1 with value.


sum

public static final int sum(int[] target)
Returns the sum of target.


sum

public static final int sum(int[] target,
                            int position,
                            int length)
Returns the sum of target from postion to postion+length-1.


min

public static final int min(int[] target)
Returns the minimum of target/.


min

public static final int min(int[] target,
                            int position,
                            int length)
Returns the minimum of target from postion to postion+length-1.


max

public static final int max(int[] target)
Returns the maximum of target.


max

public static final int max(int[] target,
                            int position,
                            int length)
Returns the maximum of target from postion to postion+length-1.