gnu.lists
Class Pair

java.lang.Object
  extended by gnu.lists.AbstractSequence
      extended by gnu.lists.ExtSequence
          extended by gnu.lists.LList
              extended by gnu.lists.Pair
All Implemented Interfaces:
Consumable, Sequence, java.io.Externalizable, java.io.Serializable, java.lang.Comparable, java.lang.Iterable, java.util.Collection, java.util.List
Direct Known Subclasses:
PairWithPosition

public class Pair
extends LList
implements java.io.Externalizable

A "pair" object, as used in Lisp-like languages. When used to implement a list, the 'car' field contains an element's value, and the 'cdr' field points to either the next Pair or LList.Empty (which represents the end of the list). (The names "car" and "cdr" [pronounced "coulder"] are historical; better names might be "value" and "next".) While a Pair is normally usued to implement a linked list, sometimes the 'cdr' field ponus to some other non-list object; this is traditionally callled a "dotted list".

See Also:
Serialized Form

Field Summary
 java.lang.Object car
           
 java.lang.Object cdr
           
 
Fields inherited from class gnu.lists.LList
Empty
 
Fields inherited from interface gnu.lists.Sequence
ATTRIBUTE_VALUE, BOOLEAN_VALUE, CDATA_VALUE, CHAR_VALUE, COMMENT_VALUE, DOCUMENT_VALUE, DOUBLE_VALUE, ELEMENT_VALUE, EOF_VALUE, eofValue, FLOAT_VALUE, INT_S16_VALUE, INT_S32_VALUE, INT_S64_VALUE, INT_S8_VALUE, INT_U16_VALUE, INT_U32_VALUE, INT_U64_VALUE, INT_U8_VALUE, OBJECT_VALUE, PRIM_VALUE, PROCESSING_INSTRUCTION_VALUE, TEXT_BYTE_VALUE
 
Constructor Summary
Pair()
           
Pair(java.lang.Object carval, java.lang.Object cdrval)
           
 
Method Summary
 int compareTo(java.lang.Object obj)
           
static int compareTo(Pair pair1, Pair pair2)
           
 boolean equals(java.lang.Object obj)
           
static boolean equals(Pair pair1, Pair pair2)
           
 java.lang.Object get(int index)
          See java.util.List.
 java.lang.Object getPosNext(int ipos)
          Get the element following the specified position.
 java.lang.Object getPosPrevious(int ipos)
          Get the element before the specified position.
 int hashCode()
           
 boolean hasNext(int ipos)
           
 boolean isEmpty()
          True is this sequence contains no elements.
 Pair lastPair()
           
 int length()
           
static Pair make(java.lang.Object car, java.lang.Object cdr)
           
 int nextPos(int ipos)
          Return the next position following the argument.
 void readExternal(java.io.ObjectInput in)
           
 java.lang.Object readResolve()
          Needed to override readResolve in LList.
 int size()
          See java.util.List.
 java.lang.Object[] toArray()
           
 java.lang.Object[] toArray(java.lang.Object[] arr)
           
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class gnu.lists.LList
chain1, chain4, checkNonList, consume, consX, createPos, createRelativePos, getIterator, length, list1, list2, list3, list4, listLength, listTail, makeList, makeList, makeList, reverseInPlace, setPosNext, setPosPrevious, toString
 
Methods inherited from class gnu.lists.ExtSequence
copyPos, isAfterPos, nextIndex, releasePos
 
Methods inherited from class gnu.lists.AbstractSequence
add, add, addAll, addAll, addPos, clear, compare, compare, compare, consumeNext, consumePosRange, contains, containsAll, elements, endPos, equals, fill, fill, fillPosRange, firstAttributePos, firstChildPos, firstChildPos, fromEndIndex, get, getAttribute, getAttributeLength, getContainingSequenceSize, getEffectiveIndex, getIndexDifference, getIterator, getIteratorAtPos, getLowBound, getNextKind, getNextTypeName, getNextTypeObject, getSize, gotoAttributesStart, gotoChildrenStart, gotoParent, hasPrevious, indexOf, iterator, lastIndexOf, listIterator, listIterator, nextIndex, nextMatching, parentPos, previousPos, rank, remove, remove, removeAll, removePos, removePosRange, retainAll, set, set, stableCompare, startPos, subList, subSequence, subSequencePos, toString, unsupported, unsupportedException
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface gnu.lists.Sequence
elements, fill, set
 
Methods inherited from interface java.util.List
add, add, addAll, addAll, clear, contains, containsAll, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, retainAll, subList
 

Field Detail

car

public java.lang.Object car

cdr

public java.lang.Object cdr
Constructor Detail

Pair

public Pair(java.lang.Object carval,
            java.lang.Object cdrval)

Pair

public Pair()
Method Detail

size

public int size()
Description copied from class: AbstractSequence
See java.util.List.

Specified by:
size in interface Sequence
Specified by:
size in interface java.util.Collection
Specified by:
size in interface java.util.List
Overrides:
size in class LList

isEmpty

public boolean isEmpty()
Description copied from interface: Sequence
True is this sequence contains no elements.

Specified by:
isEmpty in interface Sequence
Specified by:
isEmpty in interface java.util.Collection
Specified by:
isEmpty in interface java.util.List
Overrides:
isEmpty in class LList

length

public int length()

hasNext

public boolean hasNext(int ipos)
Overrides:
hasNext in class LList

nextPos

public int nextPos(int ipos)
Description copied from class: AbstractSequence
Return the next position following the argument. The new position has the isAfter property. The argument is implicitly released (as in releasePos). Returns 0 if we are already at end of file.

Overrides:
nextPos in class LList

getPosNext

public java.lang.Object getPosNext(int ipos)
Description copied from class: AbstractSequence
Get the element following the specified position.

Overrides:
getPosNext in class LList
Parameters:
ipos - the specified position.
Returns:
the following element, or eofValue if there is none. Called by SeqPosition.getNext.

getPosPrevious

public java.lang.Object getPosPrevious(int ipos)
Description copied from class: AbstractSequence
Get the element before the specified position.

Overrides:
getPosPrevious in class LList
Parameters:
ipos - the specified position.
Returns:
the following element, or eofValue if there is none.

lastPair

public final Pair lastPair()

hashCode

public int hashCode()
Specified by:
hashCode in interface java.util.Collection
Specified by:
hashCode in interface java.util.List
Overrides:
hashCode in class AbstractSequence

equals

public static boolean equals(Pair pair1,
                             Pair pair2)

compareTo

public static int compareTo(Pair pair1,
                            Pair pair2)

compareTo

public int compareTo(java.lang.Object obj)
Specified by:
compareTo in interface java.lang.Comparable
Overrides:
compareTo in class LList

get

public java.lang.Object get(int index)
Description copied from class: AbstractSequence
See java.util.List.

Specified by:
get in interface Sequence
Specified by:
get in interface java.util.List
Overrides:
get in class LList

equals

public boolean equals(java.lang.Object obj)
Specified by:
equals in interface java.util.Collection
Specified by:
equals in interface java.util.List
Overrides:
equals in class LList

make

public static Pair make(java.lang.Object car,
                        java.lang.Object cdr)

toArray

public java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.Collection
Specified by:
toArray in interface java.util.List
Overrides:
toArray in class AbstractSequence

toArray

public java.lang.Object[] toArray(java.lang.Object[] arr)
Specified by:
toArray in interface java.util.Collection
Specified by:
toArray in interface java.util.List
Overrides:
toArray in class AbstractSequence

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable
Overrides:
writeExternal in class LList
Throws:
java.io.IOException

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable
Overrides:
readExternal in class LList
Throws:
java.io.IOException
java.lang.ClassNotFoundException

readResolve

public java.lang.Object readResolve()
                             throws java.io.ObjectStreamException
Needed to override readResolve in LList.

Overrides:
readResolve in class LList
Throws:
java.io.ObjectStreamException