utilMDE
Class ArraysMDE

Object
  extended by ArraysMDE

public final class ArraysMDE
extends Object

Utilities for manipulating arrays. This complements @link{java.util.Arrays}. Also, some routines also handle Collections.


Nested Class Summary
static class ArraysMDE.ComparableArrayComparatorLengthFirst<T extends Comparable<T>>
          Note: this comparator imposes orderings that are inconsistent with equals.
static class ArraysMDE.ComparableArrayComparatorLexical<T extends Comparable<T>>
          Note: this comparator imposes orderings that are inconsistent with equals.
static class ArraysMDE.DoubleArrayComparatorLexical
          Note: this comparator imposes orderings that are inconsistent with equals.
static class ArraysMDE.IntArrayComparatorLengthFirst
          Note: this comparator imposes orderings that are inconsistent with equals.
static class ArraysMDE.IntArrayComparatorLexical
          Note: this comparator imposes orderings that are inconsistent with equals.
static class ArraysMDE.LongArrayComparatorLengthFirst
          Note: this comparator imposes orderings that are inconsistent with equals.
static class ArraysMDE.LongArrayComparatorLexical
          Note: this comparator imposes orderings that are inconsistent with equals.
static class ArraysMDE.ObjectArrayComparatorLengthFirst
          Note: this comparator imposes orderings that are inconsistent with equals.
static class ArraysMDE.ObjectArrayComparatorLexical
          Note: this comparator imposes orderings that are inconsistent with equals.
static class ArraysMDE.StringArrayComparatorLexical
          Note: this comparator imposes orderings that are inconsistent with equals.
 
Field Summary
 Vector<?> javadocLossage
           
 
Method Summary
static boolean all_null(List<?> a)
           
static boolean all_null(Object[] a)
           
static boolean any_null(List<?> a)
           
static boolean any_null(Object[] a)
           
static boolean[] concat(boolean[] a, boolean[] b)
          Return an array that contains all the elements of both argument arrays, in order.
static byte[] concat(byte[] a, byte[] b)
          Return an array that contains all the elements of both argument arrays, in order.
static char[] concat(char[] a, char[] b)
          Return an array that contains all the elements of both argument arrays, in order.
static double[] concat(double[] a, double[] b)
          Return an array that contains all the elements of both argument arrays, in order.
static float[] concat(float[] a, float[] b)
          Return an array that contains all the elements of both argument arrays, in order.
static int[] concat(int[] a, int[] b)
          Return an array that contains all the elements of both argument arrays, in order.
static
<T> T[]
concat(List<T> a, List<T> b)
          Return an array that contains all the elements of both argument arrays, in order.
static
<T> T[]
concat(List<T> a, T[] b)
          Return an array that contains all the elements of both argument arrays, in order.
static long[] concat(long[] a, long[] b)
          Return an array that contains all the elements of both argument arrays, in order.
static short[] concat(short[] a, short[] b)
          Return an array that contains all the elements of both argument arrays, in order.
static String[] concat(String[] a, String[] b)
          Return an array that contains all the elements of both argument arrays, in order.
static
<T> T[]
concat(T[] a, List<T> b)
          Return an array that contains all the elements of both argument arrays, in order.
static
<T> T[]
concat(T[] a, T[] b)
          Return an array that contains all the elements of both argument arrays, in order.
static int element_range(int[] a)
          Return the difference between the smallest and largest array elements.
static long element_range(long[] a)
          Return the difference between the smallest and largest array elements.
static int[] fn_compose(int[] a, int[] b)
           
static int[] fn_identity(int length)
           
static int[] fn_inverse_permutation(int[] a)
          Requires that fn_is_permutation(a) holds.
static int[] fn_inverse(int[] a, int arange)
           
static boolean fn_is_permutation(int[] a)
           
static boolean fn_is_total(int[] a)
           
static int indexOf(boolean[] a, boolean elt)
          Searches for the first occurence of the given element in the array.
static int indexOf(boolean[] a, boolean[] sub)
          Searches for the first subsequence of the array that matches the given array elementwise.
static int indexOf(boolean[] a, boolean elt, int minindex, int indexlimit)
          Searches for the first occurence of the given element in the array.
static int indexOf(double[] a, double elt)
          Searches for the first occurence of the given element in the array.
static int indexOf(double[] a, double[] sub)
          Searches for the first subsequence of the array that matches the given array elementwise.
static int indexOf(int[] a, int elt)
          Searches for the first occurence of the given element in the array.
static int indexOf(int[] a, int[] sub)
          Searches for the first subsequence of the array that matches the given array elementwise.
static int indexOf(int[] a, int elt, int minindex, int indexlimit)
          Searches for the first occurence of the given element in the array.
static int indexOf(List<?> a, List<?> sub)
          Searches for the first subsequence of the list that matches the given list elementwise, testing for equality using the equals method.
static int indexOf(List<?> a, Object[] sub)
          Searches for the first subsequence of the list that matches the given array elementwise, testing for equality using the equals method.
static int indexOf(List<? extends Object> a, Object elt)
          Searches for the first occurence of the given element in the list, testing for equality using the equals method.
static int indexOf(List<? extends Object> a, Object elt, int minindex, int indexlimit)
          Searches for the first occurence of the given element in the list, testing for equality using the equals method.
static int indexOf(long[] a, long elt)
          Searches for the first occurence of the given element in the array.
static int indexOf(long[] a, long[] sub)
          Searches for the first subsequence of the array that matches the given array elementwise.
static int indexOf(long[] a, long elt, int minindex, int indexlimit)
          Searches for the first occurence of the given element in the array.
static int indexOf(Object[] a, List<?> sub)
          Searches for the first subsequence of the array that matches the given list elementwise, testing for equality using the equals method.
static int indexOf(Object[] a, Object[] sub)
          Searches for the first subsequence of the array that matches the given array elementwise, testing for equality using the equals method.
static
<T> int
indexOf(T[] a, Object elt)
          Searches for the first occurence of the given element in the array, testing for equality using the equals method.
static
<T> int
indexOf(T[] a, Object elt, int minindex, int indexlimit)
          Searches for the first occurence of the given element in the array, testing for equality using the equals method.
static int indexOfEq(List<?> a, List<?> sub)
          Searches for the first subsequence of the list that matches the given list elementwise, testing for equality using == (not the equals method).
static int indexOfEq(List<?> a, Object[] sub)
          Searches for the first subsequence of the list that matches the given array elementwise, testing for equality using == (not the equals method).
static int indexOfEq(List<? extends Object> a, Object elt)
          Searches for the first occurence of the given element in the list, testing for equality using == (not the equals method).
static int indexOfEq(List<? extends Object> a, Object elt, int minindex, int indexlimit)
          Searches for the first occurence of the given element in the list, testing for equality using == (not the equals method).
static int indexOfEq(Object[] a, List<?> sub)
          Searches for the first subsequence of the array that matches the given list elementwise, testing for equality using == (not the equals method).
static int indexOfEq(Object[] a, Object elt)
          Searches for the first occurence of the given element in the array, testing for equality using == (not the equals method).
static int indexOfEq(Object[] a, Object[] sub)
          Searches for the first subsequence of the array that matches the given array elementwise, testing for equality using == (not the equals method).
static int indexOfEq(Object[] a, Object elt, int minindex, int indexlimit)
          Searches for the first occurence of the given element in the array, testing for equality using == (not the equals method).
static boolean isSubarray(boolean[] a, boolean[] sub, int a_offset)
          Determines whether the second array is a subarray of the first, starting at the specified index of the first.
static boolean isSubarray(double[] a, double[] sub, int a_offset)
          Determines whether the second array is a subarray of the first, starting at the specified index of the first.
static boolean isSubarray(int[] a, int[] sub, int a_offset)
          Determines whether the second array is a subarray of the first, starting at the specified index of the first.
static boolean isSubarray(List<?> a, List<?> sub, int a_offset)
          Determines whether the second array is a subarray of the first, starting at the specified index of the first, testing for equality using the equals method.
static boolean isSubarray(List<?> a, Object[] sub, int a_offset)
          Determines whether the second array is a subarray of the first, starting at the specified index of the first, testing for equality using the equals method.
static boolean isSubarray(long[] a, long[] sub, int a_offset)
          Determines whether the second array is a subarray of the first, starting at the specified index of the first.
static boolean isSubarray(Object[] a, List<?> sub, int a_offset)
          Determines whether the second array is a subarray of the first, starting at the specified index of the first, testing for equality using the equals method.
static boolean isSubarray(Object[] a, Object[] sub, int a_offset)
          Determines whether the second array is a subarray of the first, starting at the specified index of the first, testing for equality using the equals method.
static boolean isSubarrayEq(List<?> a, List<?> sub, int a_offset)
          Determines whether the second array is a subarray of the first, starting at the specified index of the first, testing for equality using == (not the equals method).
static boolean isSubarrayEq(List<?> a, Object[] sub, int a_offset)
          Determines whether the second array is a subarray of the first, starting at the specified index of the first, testing for equality using == (not the equals method).
static boolean isSubarrayEq(Object[] a, List<?> sub, int a_offset)
          Determines whether the second array is a subarray of the first, starting at the specified index of the first, testing for equality using == (not the equals method).
static boolean isSubarrayEq(Object[] a, Object[] sub, int a_offset)
          Determines whether the second array is a subarray of the first, starting at the specified index of the first, testing for equality using == (not the equals method).
static boolean isSubset(double[] smaller, double[] bigger)
          Whether smaller is a subset of bigger.
static boolean isSubset(long[] smaller, long[] bigger)
          Whether smaller is a subset of bigger.
static boolean isSubset(String[] smaller, String[] bigger)
          Whether smaller is a subset of bigger.
static int length(Object obj)
          Casts obj down to the proper array type then calls .length.
static double max(double[] a)
          Return the largest value in the array.
static Double max(Double[] a)
          Return the largest value in the array.
static int max(int[] a)
          Return the largest value in the array.
static Integer max(Integer[] a)
          Return the largest value in the array.
static long max(long[] a)
          Return the largest value in the array.
static Long max(Long[] a)
          Return the largest value in the array.
static int[] min_max(int[] a)
          Return a two-element array containing the smallest and largest values in the array.
static long[] min_max(long[] a)
          Return a two-element array containing the smallest and largest values in the array.
static double min(double[] a)
          Return the smallest value in the array.
static Double min(Double[] a)
          Return the smallest value in the array.
static int min(int[] a)
          Return the smallest value in the array.
static Integer min(Integer[] a)
          Return the smallest value in the array.
static long min(long[] a)
          Return the smallest value in the array.
static Long min(Long[] a)
          Return the smallest value in the array.
static boolean noDuplicates(boolean[] a)
           
static boolean noDuplicates(byte[] a)
           
static boolean noDuplicates(char[] a)
           
static boolean noDuplicates(double[] a)
           
static boolean noDuplicates(float[] a)
           
static boolean noDuplicates(int[] a)
           
static
<T> boolean
noDuplicates(List<T> a)
           
static boolean noDuplicates(long[] a)
           
static boolean noDuplicates(Object[] a)
           
static boolean noDuplicates(short[] a)
           
static boolean noDuplicates(String[] a)
           
static boolean sorted_descending(int[] a)
           
static boolean sorted_descending(long[] a)
           
static boolean sorted(int[] a)
           
static boolean sorted(long[] a)
           
static boolean[] subarray(boolean[] a, int startindex, int length)
          Return a subarray of the given array.
static byte[] subarray(byte[] a, int startindex, int length)
          Return a subarray of the given array.
static char[] subarray(char[] a, int startindex, int length)
          Return a subarray of the given array.
static double[] subarray(double[] a, int startindex, int length)
          Return a subarray of the given array.
static float[] subarray(float[] a, int startindex, int length)
          Return a subarray of the given array.
static int[] subarray(int[] a, int startindex, int length)
          Return a subarray of the given array.
static
<T> List<T>
subarray(List<T> a, int startindex, int length)
          Return a sublist of the given list.
static long[] subarray(long[] a, int startindex, int length)
          Return a subarray of the given array.
static Object[] subarray(Object[] a, int startindex, int length)
          Return a subarray of the given array.
static short[] subarray(short[] a, int startindex, int length)
          Return a subarray of the given array.
static String[] subarray(String[] a, int startindex, int length)
          Return a subarray of the given array.
static double sum(double[] a)
           
static double sum(double[][] a)
           
static int sum(int[] a)
           
static int sum(int[][] a)
           
static String toString(boolean[] a)
          Return a string representation of the array.
static String toString(double[] a)
          Return a string representation of the array.
static String toString(float[] a)
          Return a string representation of the array.
static String toString(int[] a)
          Return a string representation of the array.
static String toString(List<?> a)
          Return a string representation of the array.
static String toString(List<?> a, boolean quoted)
          Return a string representation of the array.
static String toString(long[] a)
          Return a string representation of the array.
static String toString(Object obj)
          Casts obj down to the proper array type then calls the appropriate toString() method.
static String toString(Object[] a)
          Return a string representation of the array.
static String toString(Object[] a, boolean quoted)
          Return a string representation of the array.
static String toStringQuoted(List<?> a)
          Return a string representation of the array.
static String toStringQuoted(Object[] a)
          Return a string representation of the array.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

javadocLossage

public Vector<?> javadocLossage
Method Detail

min

public static int min(int[] a)
Return the smallest value in the array.

Throws:
ArrayIndexOutOfBoundsException - if the array has length 0

min

public static long min(long[] a)
Return the smallest value in the array.

Throws:
ArrayIndexOutOfBoundsException - if the array has length 0

min

public static double min(double[] a)
Return the smallest value in the array.

Throws:
ArrayIndexOutOfBoundsException - if the array has length 0

min

public static Integer min(Integer[] a)
Return the smallest value in the array.

Throws:
ArrayIndexOutOfBoundsException - if the array has length 0

min

public static Long min(Long[] a)
Return the smallest value in the array.

Throws:
ArrayIndexOutOfBoundsException - if the array has length 0

min

public static Double min(Double[] a)
Return the smallest value in the array.

Throws:
ArrayIndexOutOfBoundsException - if the array has length 0

max

public static int max(int[] a)
Return the largest value in the array.

Throws:
ArrayIndexOutOfBoundsException - if the array has length 0

max

public static long max(long[] a)
Return the largest value in the array.

Throws:
ArrayIndexOutOfBoundsException - if the array has length 0

max

public static double max(double[] a)
Return the largest value in the array.

Throws:
ArrayIndexOutOfBoundsException - if the array has length 0

max

public static Integer max(Integer[] a)
Return the largest value in the array.

Throws:
ArrayIndexOutOfBoundsException - if the array has length 0

max

public static Long max(Long[] a)
Return the largest value in the array.

Throws:
ArrayIndexOutOfBoundsException - if the array has length 0

max

public static Double max(Double[] a)
Return the largest value in the array.

Throws:
ArrayIndexOutOfBoundsException - if the array has length 0

min_max

public static int[] min_max(int[] a)
Return a two-element array containing the smallest and largest values in the array. Throw ArrayIndexOutOfBoundsException if the array has length 0.


min_max

public static long[] min_max(long[] a)
Return a two-element array containing the smallest and largest values in the array. Throw ArrayIndexOutOfBoundsException if the array has length 0.


element_range

public static int element_range(int[] a)
Return the difference between the smallest and largest array elements.


element_range

public static long element_range(long[] a)
Return the difference between the smallest and largest array elements.


sum

public static int sum(int[] a)

sum

public static int sum(int[][] a)

sum

public static double sum(double[] a)

sum

public static double sum(double[][] a)

indexOf

public static <T> int indexOf(T[] a,
                              Object elt)
Searches for the first occurence of the given element in the array, testing for equality using the equals method.

Returns:
the first index whose element is equal to the specified element, or -1 if no such element is found in the array.
See Also:
List.indexOf(java.lang.Object)

indexOf

public static <T> int indexOf(T[] a,
                              Object elt,
                              int minindex,
                              int indexlimit)
Searches for the first occurence of the given element in the array, testing for equality using the equals method.

Returns:
the first index i containing the specified element, such that minindex <= i < indexlimit, or -1 if the element is not found in that section of the array.
See Also:
List.indexOf(java.lang.Object)

indexOf

public static int indexOf(List<? extends Object> a,
                          Object elt)
Searches for the first occurence of the given element in the list, testing for equality using the equals method. Identical to List.indexOf, but included for completeness.

Returns:
the first index whose element is equal to the specified element, or -1 if no such element is found in the list.
See Also:
List.indexOf(java.lang.Object)

indexOf

public static int indexOf(List<? extends Object> a,
                          Object elt,
                          int minindex,
                          int indexlimit)
Searches for the first occurence of the given element in the list, testing for equality using the equals method.

Returns:
the first index i containing the specified element, such that minindex <= i < indexlimit, or -1 if the element is not found in that section of the list.
See Also:
List.indexOf(java.lang.Object)

indexOfEq

public static int indexOfEq(Object[] a,
                            Object elt)
Searches for the first occurence of the given element in the array, testing for equality using == (not the equals method).

Returns:
the first index containing the specified element, or -1 if the element is not found in the array.
See Also:
Vector.indexOf(java.lang.Object)

indexOfEq

public static int indexOfEq(Object[] a,
                            Object elt,
                            int minindex,
                            int indexlimit)
Searches for the first occurence of the given element in the array, testing for equality using == (not the equals method).

Returns:
the first index i containing the specified element, such that minindex <= i < indexlimit, or -1 if the element is not found in that section of the array.
See Also:
Vector.indexOf(java.lang.Object)

indexOfEq

public static int indexOfEq(List<? extends Object> a,
                            Object elt)
Searches for the first occurence of the given element in the list, testing for equality using == (not the equals method).

Returns:
the first index containing the specified element, or -1 if the element is not found in the list.
See Also:
Vector.indexOf(java.lang.Object)

indexOfEq

public static int indexOfEq(List<? extends Object> a,
                            Object elt,
                            int minindex,
                            int indexlimit)
Searches for the first occurence of the given element in the list, testing for equality using == (not the equals method).

Returns:
the first index i containing the specified element, such that minindex <= i < indexlimit, or -1 if the element is not found in that section of the list.
See Also:
Vector.indexOf(java.lang.Object)

indexOf

public static int indexOf(int[] a,
                          int elt)
Searches for the first occurence of the given element in the array.

Returns:
the first index containing the specified element, or -1 if the element is not found in the array.
See Also:
Vector.indexOf(java.lang.Object)

indexOf

public static int indexOf(long[] a,
                          long elt)
Searches for the first occurence of the given element in the array.

Returns:
the first index containing the specified element, or -1 if the element is not found in the array.
See Also:
Vector.indexOf(java.lang.Object)

indexOf

public static int indexOf(int[] a,
                          int elt,
                          int minindex,
                          int indexlimit)
Searches for the first occurence of the given element in the array.

Returns:
the first index i containing the specified element, such that minindex <= i < indexlimit, or -1 if the element is not found in the array.
See Also:
Vector.indexOf(java.lang.Object)

indexOf

public static int indexOf(long[] a,
                          long elt,
                          int minindex,
                          int indexlimit)
Searches for the first occurence of the given element in the array.

Returns:
the first index i containing the specified element, such that minindex <= i < indexlimit, or -1 if the element is not found in the array.
See Also:
Vector.indexOf(java.lang.Object)

indexOf

public static int indexOf(boolean[] a,
                          boolean elt)
Searches for the first occurence of the given element in the array.

Returns:
the first index containing the specified element, or -1 if the element is not found in the array.
See Also:
Vector.indexOf(java.lang.Object)

indexOf

public static int indexOf(double[] a,
                          double elt)
Searches for the first occurence of the given element in the array.

Returns:
the first index containing the specified element, or -1 if the element is not found in the array.
See Also:
Vector.indexOf(java.lang.Object)

indexOf

public static int indexOf(boolean[] a,
                          boolean elt,
                          int minindex,
                          int indexlimit)
Searches for the first occurence of the given element in the array.

Returns:
the first index i containing the specified element, such that minindex <= i < indexlimit, or -1 if the element is not found in the array.
See Also:
Vector.indexOf(java.lang.Object)

indexOf

public static int indexOf(Object[] a,
                          Object[] sub)
Searches for the first subsequence of the array that matches the given array elementwise, testing for equality using the equals method.

Returns:
the first index at which the second array starts in the first array, or -1 if no such element is found in the array.
See Also:
Vector.indexOf(java.lang.Object), String.indexOf(java.lang.String)

indexOfEq

public static int indexOfEq(Object[] a,
                            Object[] sub)
Searches for the first subsequence of the array that matches the given array elementwise, testing for equality using == (not the equals method).

Returns:
the first index at which the second array starts in the first array, or -1 if the element is not found in the array.
See Also:
Vector.indexOf(java.lang.Object), String.indexOf(java.lang.String)

indexOf

public static int indexOf(List<?> a,
                          Object[] sub)
Searches for the first subsequence of the list that matches the given array elementwise, testing for equality using the equals method.

Returns:
the first index at which the second array starts in the first list, or -1 if no such element is found in the list.
See Also:
Vector.indexOf(java.lang.Object), String.indexOf(java.lang.String)

indexOfEq

public static int indexOfEq(List<?> a,
                            Object[] sub)
Searches for the first subsequence of the list that matches the given array elementwise, testing for equality using == (not the equals method).

Returns:
the first index at which the second array starts in the first list, or -1 if the element is not found in the list.
See Also:
Vector.indexOf(java.lang.Object), String.indexOf(java.lang.String)

indexOf

public static int indexOf(Object[] a,
                          List<?> sub)
Searches for the first subsequence of the array that matches the given list elementwise, testing for equality using the equals method.

Returns:
the first index at which the second list starts in the first array, or -1 if no such element is found in the array.
See Also:
Vector.indexOf(java.lang.Object), String.indexOf(java.lang.String)

indexOfEq

public static int indexOfEq(Object[] a,
                            List<?> sub)
Searches for the first subsequence of the array that matches the given list elementwise, testing for equality using == (not the equals method).

Returns:
the first index at which the second list starts in the first array, or -1 if the element is not found in the array.
See Also:
Vector.indexOf(java.lang.Object), String.indexOf(java.lang.String)

indexOf

public static int indexOf(List<?> a,
                          List<?> sub)
Searches for the first subsequence of the list that matches the given list elementwise, testing for equality using the equals method.

Returns:
the first index at which the second list starts in the first list, or -1 if no such element is found in the list.
See Also:
Vector.indexOf(java.lang.Object), String.indexOf(java.lang.String)

indexOfEq

public static int indexOfEq(List<?> a,
                            List<?> sub)
Searches for the first subsequence of the list that matches the given list elementwise, testing for equality using == (not the equals method).

Returns:
the first index at which the second list starts in the first list, or -1 if the element is not found in the list.
See Also:
Vector.indexOf(java.lang.Object), String.indexOf(java.lang.String)

indexOf

public static int indexOf(int[] a,
                          int[] sub)
Searches for the first subsequence of the array that matches the given array elementwise.

Returns:
the first index at which the second array starts in the first array, or -1 if the element is not found in the array.
See Also:
Vector.indexOf(java.lang.Object), String.indexOf(java.lang.String)

indexOf

public static int indexOf(double[] a,
                          double[] sub)
Searches for the first subsequence of the array that matches the given array elementwise.

Returns:
the first index at which the second array starts in the first array, or -1 if the element is not found in the array.
See Also:
Vector.indexOf(java.lang.Object), String.indexOf(java.lang.String)

indexOf

public static int indexOf(long[] a,
                          long[] sub)
Searches for the first subsequence of the array that matches the given array elementwise.

Returns:
the first index at which the second array starts in the first array, or -1 if the element is not found in the array.
See Also:
Vector.indexOf(java.lang.Object), String.indexOf(java.lang.String)

indexOf

public static int indexOf(boolean[] a,
                          boolean[] sub)
Searches for the first subsequence of the array that matches the given array elementwise.

Returns:
the first index containing the specified element, or -1 if the element is not found in the array.
See Also:
Vector.indexOf(java.lang.Object), String.indexOf(java.lang.String)

subarray

public static Object[] subarray(Object[] a,
                                int startindex,
                                int length)
Return a subarray of the given array.

Parameters:
a - the original array
startindex - the first index to be included
length - the number of elements to include (not an end index, to avoid confusion over whether it would be the last included index or the first non-included index)

subarray

public static <T> List<T> subarray(List<T> a,
                                   int startindex,
                                   int length)
Return a sublist of the given list.

Parameters:
a - the original list
startindex - the first index to be included
length - the number of elements to include (not an end index, to avoid confusion over whether it would be the last included index or the first non-included index)

subarray

public static String[] subarray(String[] a,
                                int startindex,
                                int length)
Return a subarray of the given array.

Parameters:
a - the original array
startindex - the first index to be included
length - the number of elements to include (not an end index, to avoid confusion over whether it would be the last included index or the first non-included index)

subarray

public static byte[] subarray(byte[] a,
                              int startindex,
                              int length)
Return a subarray of the given array.

Parameters:
a - the original array
startindex - the first index to be included
length - the number of elements to include (not an end index, to avoid confusion over whether it would be the last included index or the first non-included index)

subarray

public static boolean[] subarray(boolean[] a,
                                 int startindex,
                                 int length)
Return a subarray of the given array.

Parameters:
a - the original array
startindex - the first index to be included
length - the number of elements to include (not an end index, to avoid confusion over whether it would be the last included index or the first non-included index)

subarray

public static char[] subarray(char[] a,
                              int startindex,
                              int length)
Return a subarray of the given array.

Parameters:
a - the original array
startindex - the first index to be included
length - the number of elements to include (not an end index, to avoid confusion over whether it would be the last included index or the first non-included index)

subarray

public static double[] subarray(double[] a,
                                int startindex,
                                int length)
Return a subarray of the given array.

Parameters:
a - the original array
startindex - the first index to be included
length - the number of elements to include (not an end index, to avoid confusion over whether it would be the last included index or the first non-included index)

subarray

public static float[] subarray(float[] a,
                               int startindex,
                               int length)
Return a subarray of the given array.

Parameters:
a - the original array
startindex - the first index to be included
length - the number of elements to include (not an end index, to avoid confusion over whether it would be the last included index or the first non-included index)

subarray

public static int[] subarray(int[] a,
                             int startindex,
                             int length)
Return a subarray of the given array.

Parameters:
a - the original array
startindex - the first index to be included
length - the number of elements to include (not an end index, to avoid confusion over whether it would be the last included index or the first non-included index)

subarray

public static long[] subarray(long[] a,
                              int startindex,
                              int length)
Return a subarray of the given array.

Parameters:
a - the original array
startindex - the first index to be included
length - the number of elements to include (not an end index, to avoid confusion over whether it would be the last included index or the first non-included index)

subarray

public static short[] subarray(short[] a,
                               int startindex,
                               int length)
Return a subarray of the given array.

Parameters:
a - the original array
startindex - the first index to be included
length - the number of elements to include (not an end index, to avoid confusion over whether it would be the last included index or the first non-included index)

isSubarray

public static boolean isSubarray(Object[] a,
                                 Object[] sub,
                                 int a_offset)
Determines whether the second array is a subarray of the first, starting at the specified index of the first, testing for equality using the equals method.

Returns:
the first index at which the second array starts in the first array, or -1 if no such element is found in the array.

isSubarrayEq

public static boolean isSubarrayEq(Object[] a,
                                   Object[] sub,
                                   int a_offset)
Determines whether the second array is a subarray of the first, starting at the specified index of the first, testing for equality using == (not the equals method).

Returns:
the first index at which the second array starts in the first array, or -1 if the element is not found in the array.

isSubarray

public static boolean isSubarray(Object[] a,
                                 List<?> sub,
                                 int a_offset)
Determines whether the second array is a subarray of the first, starting at the specified index of the first, testing for equality using the equals method.

Returns:
the first index at which the second array starts in the first array, or -1 if no such element is found in the array.

isSubarrayEq

public static boolean isSubarrayEq(Object[] a,
                                   List<?> sub,
                                   int a_offset)
Determines whether the second array is a subarray of the first, starting at the specified index of the first, testing for equality using == (not the equals method).

Returns:
the first index at which the second array starts in the first array, or -1 if the element is not found in the array.

isSubarray

public static boolean isSubarray(List<?> a,
                                 Object[] sub,
                                 int a_offset)
Determines whether the second array is a subarray of the first, starting at the specified index of the first, testing for equality using the equals method.

Returns:
the first index at which the second array starts in the first array, or -1 if no such element is found in the array.

isSubarrayEq

public static boolean isSubarrayEq(List<?> a,
                                   Object[] sub,
                                   int a_offset)
Determines whether the second array is a subarray of the first, starting at the specified index of the first, testing for equality using == (not the equals method).

Returns:
the first index at which the second array starts in the first array, or -1 if the element is not found in the array.

isSubarray

public static boolean isSubarray(List<?> a,
                                 List<?> sub,
                                 int a_offset)
Determines whether the second array is a subarray of the first, starting at the specified index of the first, testing for equality using the equals method.

Returns:
the first index at which the second array starts in the first array, or -1 if no such element is found in the array.

isSubarrayEq

public static boolean isSubarrayEq(List<?> a,
                                   List<?> sub,
                                   int a_offset)
Determines whether the second array is a subarray of the first, starting at the specified index of the first, testing for equality using == (not the equals method).

Returns:
the first index at which the second array starts in the first array, or -1 if the element is not found in the array.

isSubarray

public static boolean isSubarray(int[] a,
                                 int[] sub,
                                 int a_offset)
Determines whether the second array is a subarray of the first, starting at the specified index of the first.

Returns:
the first index at which the second array starts in the first array, or -1 if the element is not found in the array.

isSubarray

public static boolean isSubarray(long[] a,
                                 long[] sub,
                                 int a_offset)
Determines whether the second array is a subarray of the first, starting at the specified index of the first.

Returns:
the first index at which the second array starts in the first array, or -1 if the element is not found in the array.

isSubarray

public static boolean isSubarray(double[] a,
                                 double[] sub,
                                 int a_offset)
Determines whether the second array is a subarray of the first, starting at the specified index of the first.

Returns:
the first index at which the second array starts in the first array, or -1 if the element is not found in the array.

isSubarray

public static boolean isSubarray(boolean[] a,
                                 boolean[] sub,
                                 int a_offset)
Determines whether the second array is a subarray of the first, starting at the specified index of the first.

Returns:
the first index at which the second array starts in the first array, or -1 if the element is not found in the array.

concat

public static <T> T[] concat(T[] a,
                             T[] b)
Return an array that contains all the elements of both argument arrays, in order. Returns a new array unless one argument is null, in which case it returns the other array.


concat

public static <T> T[] concat(T[] a,
                             List<T> b)
Return an array that contains all the elements of both argument arrays, in order. Returns a new array unless one argument is null, in which case it returns the other array.


concat

public static <T> T[] concat(List<T> a,
                             T[] b)
Return an array that contains all the elements of both argument arrays, in order. Returns a new array unless one argument is null, in which case it returns the other array.


concat

public static <T> T[] concat(List<T> a,
                             List<T> b)
Return an array that contains all the elements of both argument arrays, in order. Returns a new array unless one argument is null, in which case it returns the other array.


concat

public static String[] concat(String[] a,
                              String[] b)
Return an array that contains all the elements of both argument arrays, in order. Returns a new array unless one argument is null, in which case it returns the other array.


concat

public static byte[] concat(byte[] a,
                            byte[] b)
Return an array that contains all the elements of both argument arrays, in order. Returns a new array unless one argument is null, in which case it returns the other array.


concat

public static boolean[] concat(boolean[] a,
                               boolean[] b)
Return an array that contains all the elements of both argument arrays, in order. Returns a new array unless one argument is null, in which case it returns the other array.


concat

public static char[] concat(char[] a,
                            char[] b)
Return an array that contains all the elements of both argument arrays, in order. Returns a new array unless one argument is null, in which case it returns the other array.


concat

public static double[] concat(double[] a,
                              double[] b)
Return an array that contains all the elements of both argument arrays, in order. Returns a new array unless one argument is null, in which case it returns the other array.


concat

public static float[] concat(float[] a,
                             float[] b)
Return an array that contains all the elements of both argument arrays, in order. Returns a new array unless one argument is null, in which case it returns the other array.


concat

public static int[] concat(int[] a,
                           int[] b)
Return an array that contains all the elements of both argument arrays, in order. Returns a new array unless one argument is null, in which case it returns the other array.


concat

public static long[] concat(long[] a,
                            long[] b)
Return an array that contains all the elements of both argument arrays, in order. Returns a new array unless one argument is null, in which case it returns the other array.


concat

public static short[] concat(short[] a,
                             short[] b)
Return an array that contains all the elements of both argument arrays, in order. Returns a new array unless one argument is null, in which case it returns the other array.


toString

public static String toString(Object[] a)
Return a string representation of the array. The representation is patterned after that of java.util.Vector.

See Also:
Vector.toString()

toStringQuoted

public static String toStringQuoted(Object[] a)
Return a string representation of the array. The representation is patterned after that of java.util.Vector. Furthermore, each element is quoted like a Java String.

See Also:
Vector.toString()

toString

public static String toString(Object[] a,
                              boolean quoted)
Return a string representation of the array. The representation is patterned after that of java.util.Vector. Furthermore, if quoted is true, then each element is quoted like a Java String.

See Also:
Vector.toString()

toString

public static String toString(List<?> a)
Return a string representation of the array. The representation is patterned after that of java.util.Vector.

See Also:
Vector.toString()

toStringQuoted

public static String toStringQuoted(List<?> a)
Return a string representation of the array. The representation is patterned after that of java.util.Vector.

See Also:
Vector.toString()

toString

public static String toString(List<?> a,
                              boolean quoted)
Return a string representation of the array. The representation is patterned after that of java.util.Vector.

See Also:
Vector.toString()

toString

public static String toString(int[] a)
Return a string representation of the array. The representation is patterned after that of java.util.Vector.

See Also:
Vector.toString()

toString

public static String toString(long[] a)
Return a string representation of the array. The representation is patterned after that of java.util.Vector.

See Also:
Vector.toString()

toString

public static String toString(double[] a)
Return a string representation of the array. The representation is patterned after that of java.util.Vector.

See Also:
Vector.toString()

toString

public static String toString(float[] a)
Return a string representation of the array. The representation is patterned after that of java.util.Vector.

See Also:
Vector.toString()

toString

public static String toString(boolean[] a)
Return a string representation of the array. The representation is patterned after that of java.util.Vector.

See Also:
Vector.toString()

toString

public static String toString(Object obj)
                       throws IllegalArgumentException
Casts obj down to the proper array type then calls the appropriate toString() method. Only call this method if obj is a boolean, double, int, long, or Object array.

Throws:
IllegalArgumentException - if obj is null or is not one of the types mentioned above.

length

public static int length(Object obj)
                  throws IllegalArgumentException
Casts obj down to the proper array type then calls .length. Only call this method if obj is a boolean, double, int, long, or Object array.

Throws:
IllegalArgumentException - if obj is null or is not one of the types mentioned above.

sorted

public static boolean sorted(int[] a)

sorted

public static boolean sorted(long[] a)

sorted_descending

public static boolean sorted_descending(int[] a)

sorted_descending

public static boolean sorted_descending(long[] a)

noDuplicates

public static boolean noDuplicates(boolean[] a)
Returns:
true iff a does not contain duplicate elements using O(n) time and O(n) space.

noDuplicates

public static boolean noDuplicates(byte[] a)
Returns:
true iff a does not contain duplicate elements using O(n) time and O(n) space.

noDuplicates

public static boolean noDuplicates(char[] a)
Returns:
true iff a does not contain duplicate elements using O(n) time and O(n) space.

noDuplicates

public static boolean noDuplicates(float[] a)
Returns:
true iff a does not contain duplicate elements using O(n) time and O(n) space.

noDuplicates

public static boolean noDuplicates(short[] a)
Returns:
true iff a does not contain duplicate elements using O(n) time and O(n) space.

noDuplicates

public static boolean noDuplicates(int[] a)
Returns:
true iff a does not contain duplicate elements using O(n) time and O(n) space.

noDuplicates

public static boolean noDuplicates(double[] a)
Returns:
true iff a does not contain duplicate elements using O(n) time and O(n) space. Equality checking uses the .equals() method for java.lang.Double.

noDuplicates

public static boolean noDuplicates(long[] a)
Returns:
true iff a does not contain duplicate elements using O(n) time and O(n) space.

noDuplicates

public static boolean noDuplicates(String[] a)
Returns:
true iff a does not contain duplicate elements using O(n) time and O(n) space.

noDuplicates

public static boolean noDuplicates(Object[] a)
Returns:
true iff a does not contain duplicate elements using O(n) time and O(n) space.

noDuplicates

public static <T> boolean noDuplicates(List<T> a)
Returns:
true iff a does not contain duplicate elements using O(n) time and O(n) space.

fn_is_permutation

public static boolean fn_is_permutation(int[] a)
Returns:
true iff all elements of a are in [0..a.length) and a contains no duplicates.

fn_is_total

public static boolean fn_is_total(int[] a)
Returns:
true iff no element of a maps to -1

fn_identity

public static int[] fn_identity(int length)
Returns:
fresh array that is the identitity function of the given length

fn_inverse_permutation

public static int[] fn_inverse_permutation(int[] a)
Requires that fn_is_permutation(a) holds.

Parameters:
a - the input permutation
Returns:
fresh array which is the inverse of the given perutation.
See Also:
fn_is_permutation(int[])

fn_inverse

public static int[] fn_inverse(int[] a,
                               int arange)
Parameters:
a - function from [0..a.length) to [0..arange)
Returns:
function from [0..arange) to [0..a.length) that is the inverse of a
Throws:
UnsupportedOperationException - when the function is not invertible

fn_compose

public static int[] fn_compose(int[] a,
                               int[] b)
Parameters:
a - function from [0..a.length) to [0..b.length)
b - function from [0..b.length) to range R
Returns:
function from [0..a.length) to range R that is the composition of a and b

isSubset

public static boolean isSubset(long[] smaller,
                               long[] bigger)
Whether smaller is a subset of bigger. The implmentation is to use collections because we want to take advantage of HashSet's constant time membership tests.


isSubset

public static boolean isSubset(double[] smaller,
                               double[] bigger)
Whether smaller is a subset of bigger. The implmentation is to use collections because we want to take advantage of HashSet's constant time membership tests.


isSubset

public static boolean isSubset(String[] smaller,
                               String[] bigger)
Whether smaller is a subset of bigger. The implmentation is to use collections because we want to take advantage of HashSet's constant time membership tests.


any_null

public static boolean any_null(Object[] a)
Returns:
true iff some element of a is null (false if a is zero-sized)

all_null

public static boolean all_null(Object[] a)
Returns:
true iff all elements of a are null (unspecified result if a is zero-sized)

any_null

public static boolean any_null(List<?> a)
Returns:
true iff some element of a is null (false if a is zero-sized)

all_null

public static boolean all_null(List<?> a)
Returns:
true iff all elements of a are null (unspecified result if a is zero-sized)