JAPI 0_6-alpha-2
Yet another Java API
API Documentation

net.sf.japi.util
Class Arrays2

java.lang.Object
  extended by net.sf.japi.util.Arrays2

public final class Arrays2
extends Object

This class provides some additional utility methods you might miss in Arrays. It is named Arrays2 so you have no problems using both, this class and java.util.Arrays (no name conflict).

Author:
Christian Hujer
See Also:
Arrays

Method Summary
static int binarySearch(int[] a, int key, int low, int high)
          Searches the specified array of ints for the specified value using the binary search algorithm.
static boolean[] concat(boolean[]... a)
          Concatenate Arrays together.
static byte[] concat(byte[]... a)
          Concatenate Arrays together.
static char[] concat(char[]... a)
          Concatenate Arrays together.
static double[] concat(double[]... a)
          Concatenate Arrays together.
static float[] concat(float[]... a)
          Concatenate Arrays together.
static int[] concat(int[]... a)
          Concatenate Arrays together.
static long[] concat(long[]... a)
          Concatenate Arrays together.
static short[] concat(short[]... a)
          Concatenate Arrays together.
static
<T> T[]
concat(T[]... a)
          Concatenate Arrays together.
static
<T> int
count(Filter<T> filter, T... a)
          Count elements in an array that are accepted by the given filter.
static
<T> T[]
filter(Filter<T> filter, T... a)
          Returns an array only containing those elements accepted by the given filter.
static
<T> int
linearComparisonSearch(T o, int start, int end, T[] data, Comparator<? super T> comp)
          Perform a linear search on an array of Objects.
static
<T> int
linearComparisonSearch(T o, T[] data, Comparator<? super T> comp)
          Perform a linear search on an array of Objects.
static int linearEqualitySearch(Object o, int start, int end, Object[] data)
          Perform a linear search on an array of Objects.
static int linearEqualitySearch(Object o, Object[] data)
          Perform a linear search on an array of Objects.
static int linearIdentitySearch(Object o, int start, int end, Object[] data)
          Perform a linear search on an array of Objects.
static int linearIdentitySearch(Object o, Object[] data)
          Perform a linear search on an array of Objects.
static int linearSearch(boolean z, boolean[] data)
          Perform a linear search on an array of booleans.
static int linearSearch(boolean z, int start, int end, boolean[] data)
          Perform a linear search on an array of booleans.
static int linearSearch(byte b, byte[] data)
          Perform a linear search on an array of bytes.
static int linearSearch(byte b, int start, int end, byte[] data)
          Perform a linear search on an array of bytes.
static int linearSearch(char c, char[] data)
          Perform a linear search on an array of chars.
static int linearSearch(char c, int start, int end, char[] data)
          Perform a linear search on an array of chars.
static int linearSearch(double d, double[] data)
          Perform a linear search on an array of doubles.
static int linearSearch(double d, int start, int end, double[] data)
          Perform a linear search on an array of doubles.
static int linearSearch(float f, float[] data)
          Perform a linear search on an array of floats.
static int linearSearch(float f, int start, int end, float[] data)
          Perform a linear search on an array of floats.
static int linearSearch(int n, int[] data)
          Perform a linear search on an array of ints.
static int linearSearch(int n, int start, int end, int[] data)
          Perform a linear search on an array of ints.
static int linearSearch(long l, int start, int end, long[] data)
          Perform a linear search on an array of longs.
static int linearSearch(long l, long[] data)
          Perform a linear search on an array of longs.
static int linearSearch(short s, int start, int end, short[] data)
          Perform a linear search on an array of shorts.
static int linearSearch(short s, short[] data)
          Perform a linear search on an array of shorts.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

concat

public static double[] concat(double[]... a)
Concatenate Arrays together.

Parameters:
a - Arrays to concatenate
Returns:
new Array containing all elements of all arrays

concat

public static float[] concat(float[]... a)
Concatenate Arrays together.

Parameters:
a - Arrays to concatenate
Returns:
new Array containing all elements of all arrays

concat

public static long[] concat(long[]... a)
Concatenate Arrays together.

Parameters:
a - Arrays to concatenate
Returns:
new Array containing all elements of all arrays

concat

public static int[] concat(int[]... a)
Concatenate Arrays together.

Parameters:
a - Arrays to concatenate
Returns:
new Array containing all elements of all arrays

concat

public static short[] concat(short[]... a)
Concatenate Arrays together.

Parameters:
a - Arrays to concatenate
Returns:
new Array containing all elements of all arrays

concat

public static char[] concat(char[]... a)
Concatenate Arrays together.

Parameters:
a - Arrays to concatenate
Returns:
new Array containing all elements of all arrays

concat

public static byte[] concat(byte[]... a)
Concatenate Arrays together.

Parameters:
a - Arrays to concatenate
Returns:
new Array containing all elements of all arrays

concat

public static boolean[] concat(boolean[]... a)
Concatenate Arrays together.

Parameters:
a - Arrays to concatenate
Returns:
new Array containing all elements of all arrays

concat

public static <T> T[] concat(T[]... a)
Concatenate Arrays together.

Parameters:
a - Arrays to concatenate
Returns:
new Array containing all elements of all arrays

filter

public static <T> T[] filter(Filter<T> filter,
                             T... a)
Returns an array only containing those elements accepted by the given filter. The original array remains unmodified.

Parameters:
a - Elements to filter
filter - Filter to use for a
Returns:
array containing only those elements from a accepted by filter
See Also:
Collections2.filter(Collection,Filter)

count

public static <T> int count(Filter<T> filter,
                            T... a)
Count elements in an array that are accepted by the given filter.

Parameters:
a - Elements to count in
filter - Filter to use for a
Returns:
number of elements in a accepted by filter

binarySearch

public static int binarySearch(int[] a,
                               int key,
                               int low,
                               int high)
Searches the specified array of ints for the specified value using the binary search algorithm. The array must be sorted (as by the sort method, above) prior to making this call. If it is not sorted, the results are undefined (even a runtime exception might occur). If the array contains multiple elements with the specified value, there is no guarantee which one will be found.

Parameters:
a - the array to be searched.
key - the value to be searched for.
low - lower border (must be >= 0)
high - upper border (must be < a.length)
Returns:
index of the search key, if it is contained in the list; otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which the key would be inserted into the list: the index of the first element greater than the key, or list.size(), if all elements in the list are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
Throws:
ArrayIndexOutOfBoundsException - if low < 0 or high >= a.length
See Also:
Arrays.binarySearch(int[],int), Arrays.sort(int[])

linearSearch

public static int linearSearch(boolean z,
                               boolean[] data)
Perform a linear search on an array of booleans.

Parameters:
z - boolean to find in data
data - array of booleans to perform linear search on
Returns:
index of n in data or -1 if not found

linearSearch

public static int linearSearch(char c,
                               char[] data)
Perform a linear search on an array of chars.

Parameters:
c - char to find in data
data - array of chars to perform linear search on
Returns:
index of n in data or -1 if not found

linearSearch

public static int linearSearch(double d,
                               double[] data)
Perform a linear search on an array of doubles.

Parameters:
d - double to find in data
data - array of doubles to perform linear search on
Returns:
index of n in data or -1 if not found

linearSearch

public static int linearSearch(float f,
                               float[] data)
Perform a linear search on an array of floats.

Parameters:
f - float to find in data
data - array of floats to perform linear search on
Returns:
index of n in data or -1 if not found

linearSearch

public static int linearSearch(long l,
                               long[] data)
Perform a linear search on an array of longs.

Parameters:
l - long to find in data
data - array of longs to perform linear search on
Returns:
index of n in data or -1 if not found

linearSearch

public static int linearSearch(int n,
                               int[] data)
Perform a linear search on an array of ints.

Parameters:
n - int to find in data
data - array of ints to perform linear search on
Returns:
index of n in data or -1 if not found

linearSearch

public static int linearSearch(short s,
                               short[] data)
Perform a linear search on an array of shorts.

Parameters:
s - short to find in data
data - array of shorts to perform linear search on
Returns:
index of n in data or -1 if not found

linearSearch

public static int linearSearch(byte b,
                               byte[] data)
Perform a linear search on an array of bytes.

Parameters:
b - byte to find in data
data - array of bytes to perform linear search on
Returns:
index of n in data or -1 if not found

linearSearch

public static int linearSearch(boolean z,
                               int start,
                               int end,
                               boolean[] data)
Perform a linear search on an array of booleans.

Parameters:
z - boolean to find in data
start - start index within data
end - end index within data
data - array of booleans to perform linear search on
Returns:
index of n in data or -1 if not found
Throws:
ArrayIndexOutOfBoundsException - in case start < 0 or end >= data.length

linearSearch

public static int linearSearch(char c,
                               int start,
                               int end,
                               char[] data)
Perform a linear search on an array of chars.

Parameters:
c - char to find in data
start - start index within data
end - end index within data
data - array of chars to perform linear search on
Returns:
index of n in data or -1 if not found
Throws:
ArrayIndexOutOfBoundsException - in case start < 0 or end >= data.length

linearSearch

public static int linearSearch(double d,
                               int start,
                               int end,
                               double[] data)
Perform a linear search on an array of doubles.

Parameters:
d - double to find in data
start - start index within data
end - end index within data
data - array of doubles to perform linear search on
Returns:
index of n in data or -1 if not found
Throws:
ArrayIndexOutOfBoundsException - in case start < 0 or end >= data.length

linearSearch

public static int linearSearch(float f,
                               int start,
                               int end,
                               float[] data)
Perform a linear search on an array of floats.

Parameters:
f - float to find in data
start - start index within data
end - end index within data
data - array of floats to perform linear search on
Returns:
index of n in data or -1 if not found
Throws:
ArrayIndexOutOfBoundsException - in case start < 0 or end >= data.length

linearSearch

public static int linearSearch(long l,
                               int start,
                               int end,
                               long[] data)
Perform a linear search on an array of longs.

Parameters:
l - long to find in data
start - start index within data
end - end index within data
data - array of longs to perform linear search on
Returns:
index of n in data or -1 if not found
Throws:
ArrayIndexOutOfBoundsException - in case start < 0 or end >= data.length

linearSearch

public static int linearSearch(int n,
                               int start,
                               int end,
                               int[] data)
Perform a linear search on an array of ints.

Parameters:
n - int to find in data
start - start index within data
end - end index within data
data - array of ints to perform linear search on
Returns:
index of n in data or -1 if not found
Throws:
ArrayIndexOutOfBoundsException - in case start < 0 or end >= data.length

linearSearch

public static int linearSearch(short s,
                               int start,
                               int end,
                               short[] data)
Perform a linear search on an array of shorts.

Parameters:
s - short to find in data
start - start index within data
end - end index within data
data - array of shorts to perform linear search on
Returns:
index of n in data or -1 if not found
Throws:
ArrayIndexOutOfBoundsException - in case start < 0 or end >= data.length

linearSearch

public static int linearSearch(byte b,
                               int start,
                               int end,
                               byte[] data)
Perform a linear search on an array of bytes.

Parameters:
b - byte to find in data
start - start index within data
end - end index within data
data - array of bytes to perform linear search on
Returns:
index of n in data or -1 if not found
Throws:
ArrayIndexOutOfBoundsException - in case start < 0 or end >= data.length

linearIdentitySearch

public static int linearIdentitySearch(Object o,
                                       Object[] data)
Perform a linear search on an array of Objects.

Parameters:
o - Object to find in data
data - array of Objects to perform linear search on
Returns:
index of n in data or -1 if not found

linearIdentitySearch

public static int linearIdentitySearch(Object o,
                                       int start,
                                       int end,
                                       Object[] data)
Perform a linear search on an array of Objects.

Parameters:
o - Object to find in data
start - start index within data
end - end index within data
data - array of Objects to perform linear search on
Returns:
index of n in data or -1 if not found
Throws:
ArrayIndexOutOfBoundsException - in case start < 0 or end >= data.length

linearEqualitySearch

public static int linearEqualitySearch(Object o,
                                       Object[] data)
Perform a linear search on an array of Objects.

Parameters:
o - Object to find in data
data - array of Objects to perform linear search on
Returns:
index of n in data or -1 if not found

linearEqualitySearch

public static int linearEqualitySearch(Object o,
                                       int start,
                                       int end,
                                       Object[] data)
Perform a linear search on an array of Objects.

Parameters:
o - Object to find in data
start - start index within data
end - end index within data
data - array of Objects to perform linear search on
Returns:
index of n in data or -1 if not found
Throws:
ArrayIndexOutOfBoundsException - in case start < 0 or end >= data.length

linearComparisonSearch

public static <T> int linearComparisonSearch(T o,
                                             T[] data,
                                             Comparator<? super T> comp)
Perform a linear search on an array of Objects.

Parameters:
o - Object to find in data
data - array of Objects to perform linear search on
Returns:
index of n in data or -1 if not found

linearComparisonSearch

public static <T> int linearComparisonSearch(T o,
                                             int start,
                                             int end,
                                             T[] data,
                                             Comparator<? super T> comp)
Perform a linear search on an array of Objects.

Parameters:
o - Object to find in data
start - start index within data
end - end index within data
data - array of Objects to perform linear search on
Returns:
index of n in data or -1 if not found
Throws:
ArrayIndexOutOfBoundsException - in case start < 0 or end >= data.length

JAPI
Yet another Java API
API Documentation

© 2005-2006 Christian Hujer. All rights reserved. See copyright