com.aliasi.util
Class Tuple<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by com.aliasi.util.Tuple<E>
Type Parameters:
E - the type of object stored in the tuple
All Implemented Interfaces:
Iterable<E>, Collection<E>, List<E>

public abstract class Tuple<E>
extends AbstractList<E>

A tuple is an immutable ordered list of objects or null values with equality conditions determined pointwise.

Since:
LingPipe1.0
Version:
3.0
Author:
Bob Carpenter

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Method Summary
static
<E> Tuple<E>
create()
          Returns a zero-length tuple.
static
<E> Tuple<E>
create(E obj)
          Returns a tuple of length one containing the specified object.
static
<E> Tuple<E>
create(E[] objs)
          Creates a tuple from the specified array of objects.
static
<E> Tuple<E>
create(E o1, E o2)
          Returns a new tuple representing a pair of objects.
abstract  E get(int index)
          Returns the object at the specified index in the tuple.
 int hashCode()
          Returns the hash code for this list.
abstract  int size()
          Returns the length of the tuple.
 
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, equals, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Method Detail

size

public abstract int size()
Returns the length of the tuple.

Specified by:
size in interface Collection<E>
Specified by:
size in interface List<E>
Specified by:
size in class AbstractCollection<E>
Returns:
Number of elements in the tuple.

get

public abstract E get(int index)
Returns the object at the specified index in the tuple.

Specified by:
get in interface List<E>
Specified by:
get in class AbstractList<E>
Parameters:
index - Index of element to return.
Returns:
Object at the specified index.
Throws:
IndexOutOfBoundsException - If the index is out of bounds.

hashCode

public int hashCode()
Returns the hash code for this list. Hash codes are cached, because tuples are immutable. Subclasses that override this method must follow the specification in List.

Specified by:
hashCode in interface Collection<E>
Specified by:
hashCode in interface List<E>
Overrides:
hashCode in class AbstractList<E>
Returns:
Hash code value for this tuple.

create

public static <E> Tuple<E> create()
Returns a zero-length tuple.

Type Parameters:
E - the type of object stored in the tuple
Returns:
Zero-length tuple.

create

public static <E> Tuple<E> create(E obj)
Returns a tuple of length one containing the specified object.

Type Parameters:
E - the type of object stored in the tuple
Parameters:
obj - Object to include in tuple.
Returns:
Length one tuple containing specified object.

create

public static <E> Tuple<E> create(E[] objs)
Creates a tuple from the specified array of objects.

Type Parameters:
E - the type of object stored in the tuple
Parameters:
objs - Objects on which to base tuple.
Returns:
Tuple representing specified array of objects.

create

public static <E> Tuple<E> create(E o1,
                                  E o2)
Returns a new tuple representing a pair of objects.

Type Parameters:
E - the type of object stored in the tuple
Parameters:
o1 - First object in pair.
o2 - Second object in pair.
Returns:
Tuple consisting of the specified pair of objects.