jfun.util
Class List

java.lang.Object
  extended byjfun.util.List
All Implemented Interfaces:
java.io.Serializable, Sizeable

public abstract class List
extends java.lang.Object
implements Sizeable, java.io.Serializable

The immutable list used as jaskell list.

Author:
Ben Yu Dec 31, 2004
See Also:
Serialized Form

Field Summary
static List nil
          the empty list.
 
Constructor Summary
List()
           
 
Method Summary
 List cons(java.lang.Object obj)
          add an object to the head of the list.
 boolean equals(java.lang.Object other)
           
static List fromArray(java.lang.Object arr)
          Create a list using the elements of the array.
static List fromArray(java.lang.Object[] arr)
          Create a list using the elements of the array.
 int hashCode()
           
abstract  java.lang.Object head()
          Get the first object in the list.
abstract  boolean isEmpty()
          Tests whether it is empty.
 List rev()
          reverse the list.
abstract  List revAppend(List l)
          reverse the list and append it to the tail of list l.
 java.lang.Object[] revArray()
          convert the list to an array in reverse order.
 java.lang.Object[] revArray(int from, java.lang.Object[] arr)
          add the elements of the list to an array from a certain position in reverse order.
 java.lang.Object[] revArray(java.lang.Object[] arr)
          add the elements of the list to an array in reverse order.
abstract  int size()
          Get the size.
abstract  List tail()
          Get the tail of the list.
 java.lang.Object[] toArray()
          convert the list to an array.
 java.lang.Object[] toArray(int from, java.lang.Object[] arr)
          add the elements of the list to an array from a certain position.
 java.lang.Object[] toArray(java.lang.Object[] arr)
          add the elements of the list to an array.
 void toList(java.util.List to)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

nil

public static final List nil
the empty list.

Constructor Detail

List

public List()
Method Detail

isEmpty

public abstract boolean isEmpty()
Description copied from interface: Sizeable
Tests whether it is empty. Some class may provide a more efficient implementation than size().

Specified by:
isEmpty in interface Sizeable
Returns:
true if empty.

head

public abstract java.lang.Object head()
Get the first object in the list.

Returns:
the first object in the list.

tail

public abstract List tail()
Get the tail of the list.

Returns:
the tail.

rev

public List rev()
reverse the list.

Returns:
the reversed list.

revAppend

public abstract List revAppend(List l)
reverse the list and append it to the tail of list l.

Parameters:
l - the list to append to.
Returns:
the new list.

size

public abstract int size()
Description copied from interface: Sizeable
Get the size.

Specified by:
size in interface Sizeable
Returns:
the size.

cons

public List cons(java.lang.Object obj)
add an object to the head of the list.

Parameters:
obj - the object to add.
Returns:
the new list.

hashCode

public int hashCode()

equals

public boolean equals(java.lang.Object other)

toString

public java.lang.String toString()

toList

public void toList(java.util.List to)

toArray

public java.lang.Object[] toArray()
convert the list to an array.

Returns:
the array containing all the listr element.

toArray

public java.lang.Object[] toArray(java.lang.Object[] arr)
add the elements of the list to an array.

Parameters:
arr - the array to store the list elements.
Returns:
the same array object as the array passed in as argument.

toArray

public java.lang.Object[] toArray(int from,
                                  java.lang.Object[] arr)
add the elements of the list to an array from a certain position. The array object passed in has to have length of from+this.size().

Parameters:
from - the starting index to store list elemnt to.
arr - the array to store the list elements.
Returns:
the same array object as the array passed in as argument.

revArray

public java.lang.Object[] revArray()
convert the list to an array in reverse order.

Returns:
the array containing all the listr element.

revArray

public java.lang.Object[] revArray(java.lang.Object[] arr)
add the elements of the list to an array in reverse order.

Parameters:
arr - the array to store the list elements.
Returns:
the same array object as the array passed in as argument.

revArray

public java.lang.Object[] revArray(int from,
                                   java.lang.Object[] arr)
add the elements of the list to an array from a certain position in reverse order. The array object passed in has to have length of from+this.size().

Parameters:
from - the starting index to store list elemnt to.
arr - the array to store the list elements.
Returns:
the same array object as the array passed in as argument.

fromArray

public static List fromArray(java.lang.Object[] arr)
Create a list using the elements of the array.

Parameters:
arr - the array to populate the list.
Returns:
the List object.

fromArray

public static List fromArray(java.lang.Object arr)
Create a list using the elements of the array.

Parameters:
arr - the array to populate the list. It can be any array including array of primitive types.
Returns:
the List object.