info.javelot.functionalj.util
Class Lists

java.lang.Object
  extended byinfo.javelot.functionalj.util.Lists

public final class Lists
extends Object

Methods concerning Collections, Lists and Sets.

Author:
Copyright © 2006 Frederic Daoud

Field Summary
static Function1 sizeOf
           
 
Method Summary
static boolean[] asBooleanArray(Collection p_coll)
          Returns an array of booleans from a collection of Booleans.
static byte[] asByteArray(Collection p_coll)
          Returns an array of bytes from a collection of Bytes.
static char[] asCharArray(Collection p_coll)
          Returns an array of chars from a collection of Characters.
static double[] asDoubleArray(Collection p_coll)
          Returns an array of doubles from a collection of Doubles.
static float[] asFloatArray(Collection p_coll)
          Returns an array of floats from a collection of Floats.
static int[] asIntArray(Collection p_coll)
          Returns an array of ints from a collection of Integers.
static List asList(boolean[] p_booleans)
          Returns a List of Booleans from an array of booleans.
static List asList(byte[] p_bytes)
          Returns a List of Bytes from an array of bytes.
static List asList(char[] p_chars)
          Returns a List of Characters from an array of chars.
static List asList(double[] p_doubles)
          Returns a List of Doubles from an array of doubles.
static List asList(float[] p_floats)
          Returns a List of Floats from an array of floats.
static List asList(int[] p_ints)
          Returns a List of Integers from an array of ints.
static List asList(long[] p_longs)
          Returns a List of Longs from an array of longs.
static List asList(Object[] p_objects)
          Returns a List from an array of Objects, returning an empty List if the array is null.
static List asList(short[] p_shorts)
          Returns a List of Shorts from an array of shorts.
static List asList(String p_string)
          Returns a List of Characters from a String.
static long[] asLongArray(Collection p_coll)
          Returns an array of longs from a collection of Longs.
static short[] asShortArray(Collection p_coll)
          Returns an array of shorts from a collection of Shorts.
static Object[] concat(Object[] p_array1, Object[] p_array2)
          Combines two arrays of parameters into one by concatenating the two, treating null arrays as zero-length arrays.
static Object first(Collection p_collection)
          Returns the first element of a collection.
static Object first(Object[] p_array)
          Version of first(Collection) which accepts an array.
static List init(Collection p_collection)
          Returns the initial of a collection, that is, all elements except the last.
static List init(Object[] p_array)
          Version of init(Collection) which accepts an array.
static Object[] initArray(Object[] p_array)
          Version of init(Collection) which accepts an array and returns an array, without using an intermediate Collection.
static Iterator iterator(Collection p_collection)
          Returns the Iterator for the specified list, or an empty iterator if the list is null, to avoid NullPointerExceptions.
static Iterator iterator(Object[] p_array)
          Returns the Iterator for the specified array, or an empty iterator if the array is null, to avoid NullPointerExceptions.
static Object last(Collection p_collection)
          Returns the last element of a collection.
static Object last(Object[] p_array)
          Version of last(Collection) that accepts an array.
static int sizeOf(Collection p_collection)
          Returns the size of a collection, returning zero if the list is null.
static int sizeOf(Object[] p_array)
          Returns the size of a array, returning zero if the array is null.
static Pair splitAt(int p_index, List p_list)
          Splits a list in two at the specified index, returning a pair of lists.
static Pair splitAt(int p_index, Object[] p_array)
          Version of splitAt(int, List) that accepts an array.
static Pair splitAtArray(int p_index, Object[] p_array)
          Version of splitAt(int, List) that accepts an array and returns a Pair of arrays, without using an intermediate Collection.
static List tail(Collection p_collection)
          Returns the tail of a collection, that is, all elements except the first.
static List tail(Object[] p_array)
          Version of tail(Collection) which accepts an array.
static Object[] tailArray(Object[] p_array)
          Version of tail(Collection) which accepts an array and returns an array, without using an intermediate Collection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sizeOf

public static final Function1 sizeOf
Method Detail

first

public static Object first(Collection p_collection)
                    throws FunctionException
Returns the first element of a collection.

Parameters:
p_collection - the collection for which to return the first element.
Returns:
the first element of the collection.
Throws:
FunctionException - thrown if the collection is null or empty.

first

public static Object first(Object[] p_array)
                    throws FunctionException
Version of first(Collection) which accepts an array.

Throws:
FunctionException

last

public static Object last(Collection p_collection)
Returns the last element of a collection.

Parameters:
p_collection - the list for which to return the last element.
Returns:
the last element of the collection.
Throws:
FunctionException - thrown if the collection is null or empty.

last

public static Object last(Object[] p_array)
Version of last(Collection) that accepts an array.


init

public static List init(Collection p_collection)
Returns the initial of a collection, that is, all elements except the last.

Parameters:
p_collection - the collection for which to return the initial part.
Returns:
all elements of the collection except the last, or an empty list if the specified collection is empty.

init

public static List init(Object[] p_array)
Version of init(Collection) which accepts an array.


initArray

public static Object[] initArray(Object[] p_array)
Version of init(Collection) which accepts an array and returns an array, without using an intermediate Collection.


tail

public static List tail(Collection p_collection)
Returns the tail of a collection, that is, all elements except the first.

Parameters:
p_collection - the collection for which to return the tail.
Returns:
all elements of the collection except the first, or an empty list if the specified collection is empty.

tail

public static List tail(Object[] p_array)
Version of tail(Collection) which accepts an array.


tailArray

public static Object[] tailArray(Object[] p_array)
Version of tail(Collection) which accepts an array and returns an array, without using an intermediate Collection.


splitAt

public static Pair splitAt(int p_index,
                           List p_list)
Splits a list in two at the specified index, returning a pair of lists. The first list contains as many elements as the specified index; the second list contains the rest of the elements.

Particular cases:


splitAt

public static Pair splitAt(int p_index,
                           Object[] p_array)
Version of splitAt(int, List) that accepts an array.


splitAtArray

public static Pair splitAtArray(int p_index,
                                Object[] p_array)
Version of splitAt(int, List) that accepts an array and returns a Pair of arrays, without using an intermediate Collection.


sizeOf

public static int sizeOf(Collection p_collection)
Returns the size of a collection, returning zero if the list is null.

Parameters:
p_collection - the collection for which to return the size.
Returns:
the size of the collection, or 0 if the collection is null.

sizeOf

public static int sizeOf(Object[] p_array)
Returns the size of a array, returning zero if the array is null.

Parameters:
p_array - the array for which to return the size.
Returns:
the size of the array, or 0 if the array is null.

asList

public static List asList(Object[] p_objects)
Returns a List from an array of Objects, returning an empty List if the array is null.

Parameters:
p_objects - the array of Objects to be converted to a List.
Returns:
a List of Objects.

asList

public static List asList(boolean[] p_booleans)
Returns a List of Booleans from an array of booleans. Returns an empty list if the array is null.

Parameters:
p_booleans - the array of boolean values to be converted to a List.
Returns:
a List of Boolean objects.

asList

public static List asList(byte[] p_bytes)
Returns a List of Bytes from an array of bytes. Returns an empty list if the array is null.

Parameters:
p_bytes - the array of byte values to be converted to a List.
Returns:
a List of Byte objects.

asList

public static List asList(char[] p_chars)
Returns a List of Characters from an array of chars. Returns an empty list if the array is null.

Parameters:
p_chars - the array of char values to be converted to a List.
Returns:
a List of Character objects.

asList

public static List asList(double[] p_doubles)
Returns a List of Doubles from an array of doubles. Returns an empty list if the array is null.

Parameters:
p_doubles - the array of double values to be converted to a List.
Returns:
a List of Double objects.

asList

public static List asList(float[] p_floats)
Returns a List of Floats from an array of floats. Returns an empty list if the array is null.

Parameters:
p_floats - the array of float values to be converted to a List.
Returns:
a List of Float objects.

asList

public static List asList(int[] p_ints)
Returns a List of Integers from an array of ints. Returns an empty list if the array is null.

Parameters:
p_ints - the array of int values to be converted to a List.
Returns:
a List of Integer objects.

asList

public static List asList(long[] p_longs)
Returns a List of Longs from an array of longs. Returns an empty list if the array is null.

Parameters:
p_longs - the array of long values to be converted to a List.
Returns:
a List of Long objects.

asList

public static List asList(short[] p_shorts)
Returns a List of Shorts from an array of shorts. Returns an empty list if the array is null.

Parameters:
p_shorts - the array of short values to be converted to a List.
Returns:
a List of Short objects.

asList

public static List asList(String p_string)
Returns a List of Characters from a String. Returns an empty list if the string is null.

Parameters:
p_string - the String to be converted to a List.
Returns:
a List of Character objects.

concat

public static Object[] concat(Object[] p_array1,
                              Object[] p_array2)
Combines two arrays of parameters into one by concatenating the two, treating null arrays as zero-length arrays.

Parameters:
p_array1 - the first array.
p_array2 - the second array.
Returns:
a non-null array that combines the two arrays by concatenation.

asBooleanArray

public static boolean[] asBooleanArray(Collection p_coll)
Returns an array of booleans from a collection of Booleans. Returns an empty array if the collection is null.

Parameters:
p_coll - the collection of Booleans to be converted to an array of booleans.
Returns:
an array of booleans.

asByteArray

public static byte[] asByteArray(Collection p_coll)
Returns an array of bytes from a collection of Bytes. Returns an empty array if the collection is null.

Parameters:
p_coll - the collection of Bytes to be converted to an array of bytes.
Returns:
an array of bytes.

asCharArray

public static char[] asCharArray(Collection p_coll)
Returns an array of chars from a collection of Characters. Returns an empty array if the collection is null.

Parameters:
p_coll - the collection of Characters to be converted to an array of chars.
Returns:
an array of chars.

asDoubleArray

public static double[] asDoubleArray(Collection p_coll)
Returns an array of doubles from a collection of Doubles. Returns an empty array if the collection is null.

Parameters:
p_coll - the collection of Doubles to be converted to an array of doubles.
Returns:
an array of doubles.

asFloatArray

public static float[] asFloatArray(Collection p_coll)
Returns an array of floats from a collection of Floats. Returns an empty array if the collection is null.

Parameters:
p_coll - the collection of Floats to be converted to an array of floats.
Returns:
an array of floats.

asIntArray

public static int[] asIntArray(Collection p_coll)
Returns an array of ints from a collection of Integers. Returns an empty array if the collection is null.

Parameters:
p_coll - the collection of Integers to be converted to an array of ints.
Returns:
an array of ints.

asLongArray

public static long[] asLongArray(Collection p_coll)
Returns an array of longs from a collection of Longs. Returns an empty array if the collection is null.

Parameters:
p_coll - the collection of Longs to be converted to an array of longs.
Returns:
an array of longs.

asShortArray

public static short[] asShortArray(Collection p_coll)
Returns an array of shorts from a collection of Shorts. Returns an empty array if the collection is null.

Parameters:
p_coll - the collection of Shorts to be converted to an array of shorts.
Returns:
an array of shorts.

iterator

public static Iterator iterator(Collection p_collection)
Returns the Iterator for the specified list, or an empty iterator if the list is null, to avoid NullPointerExceptions.


iterator

public static Iterator iterator(Object[] p_array)
Returns the Iterator for the specified array, or an empty iterator if the array is null, to avoid NullPointerExceptions.