gnu.lists

Class Pair

Implemented Interfaces:
Comparable, Externalizable, java.util.List, Consumable, Sequence
Known Direct Subclasses:
PairWithPosition

public class Pair
extends LList
implements 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".

Field Summary

Object
car
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, EOF_VALUE, FLOAT_VALUE, GROUP_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, eofValue

Constructor Summary

Pair()
Do not use - only public for serialization!
Pair(Object carval, Object cdrval)

Method Summary

int
compareTo(Object obj)
static int
compareTo(Pair pair1, Pair pair2)
boolean
equals(Object obj)
static boolean
equals(Pair pair1, Pair pair2)
Object
get(int index)
See java.util.List.
Object
getPosNext(int ipos)
Get the element following the specified position.
Object
getPosPrevious(int ipos)
Get the element before the specified position.
boolean
hasNext(int ipos)
int
hashCode()
boolean
isEmpty()
Pair
lastPair()
int
length()
static Pair
make(Object car, Object cdr)
int
nextPos(int ipos)
Return the next position following the argument.
void
readExternal(ObjectInput in)
Object
readResolve()
Needed to override readResolve in LList.
int
size()
See java.util.List.
Object[]
toArray()
Object[]
toArray(Object[] arr)
void
writeExternal(ObjectOutput out)

Methods inherited from class gnu.lists.LList

chain1, chain4, checkNonList, compareTo, consume, createPos, createRelativePos, equals, get, getIterator, getPosNext, getPosPrevious, hasNext, isEmpty, length, list1, list2, list3, list4, listLength, listTail, makeList, makeList, makeList, nextPos, readExternal, readResolve, reverseInPlace, setPosNext, setPosPrevious, size, toString, writeExternal

Methods inherited from class gnu.lists.ExtSequence

copyPos, isAfterPos, nextIndex, releasePos

Methods inherited from class gnu.lists.AbstractSequence

add, add, addAll, addAll, addPos, append, baseUriOfPos, clear, compare, compare, compare, consume, consumeNext, consumePosRange, contains, containsAll, copyPos, createPos, createRelativePos, elements, endPos, equals, equals, fill, fill, fillPosRange, firstAttributePos, firstChildPos, fromEndIndex, get, get, getAttribute, getAttributeLength, getContainingSequenceSize, getEffectiveIndex, getIndexDifference, getIterator, getIterator, getIteratorAtPos, getLowBound, getNextKind, getNextTypeName, getNextTypeObject, getPosNext, getPosPrevious, getSize, gotoAttributesStart, gotoChildrenStart, gotoParent, hasNext, hasPrevious, hashCode, indexOf, isAfterPos, isEmpty, iterator, lastIndexOf, listIterator, listIterator, nextIndex, nextIndex, nextMatching, nextPos, parentPos, previousPos, rank, releasePos, remove, remove, removeAll, removePos, removePosRange, retainAll, set, set, setPosNext, setPosPrevious, size, stableCompare, startPos, subList, subSequence, subSequencePos, toArray, toArray, toString, toString, unsupported

Field Details

car

public Object car

cdr

public Object cdr

Constructor Details

Pair

public Pair()
Do not use - only public for serialization!

Pair

public Pair(Object carval,
            Object cdrval)

Method Details

compareTo

public int compareTo(Object obj)
Overrides:
compareTo in interface LList

compareTo

public static int compareTo(Pair pair1,
                            Pair pair2)

equals

public boolean equals(Object obj)
Overrides:
equals in interface LList

equals

public static boolean equals(Pair pair1,
                             Pair pair2)

get

public Object get(int index)
See java.util.List.
Specified by:
get in interface Sequence
Overrides:
get in interface LList

getPosNext

public Object getPosNext(int ipos)
Get the element following the specified position.
Overrides:
getPosNext in interface LList
Parameters:
ipos - the specified position.
Returns:
the following element, or eofValue if there is none. Called by SeqPosition.getNext.

getPosPrevious

public Object getPosPrevious(int ipos)
Get the element before the specified position.
Overrides:
getPosPrevious in interface LList
Parameters:
ipos - the specified position.
Returns:
the following element, or eofValue if there is none.

hasNext

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

hashCode

public int hashCode()
Overrides:
hashCode in interface AbstractSequence

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Sequence
Overrides:
isEmpty in interface LList

lastPair

public final Pair lastPair()

length

public int length()

make

public static Pair make(Object car,
                        Object cdr)

nextPos

public int nextPos(int ipos)
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 interface LList

readExternal

public void readExternal(ObjectInput in)
            throws IOException,
                   ClassNotFoundException
Overrides:
readExternal in interface LList

readResolve

public Object readResolve()
            throws ObjectStreamException
Needed to override readResolve in LList.
Overrides:
readResolve in interface LList

size

public int size()
See java.util.List.
Specified by:
size in interface Sequence
Overrides:
size in interface LList

toArray

public Object[] toArray()
Overrides:
toArray in interface AbstractSequence

toArray

public Object[] toArray(Object[] arr)
Overrides:
toArray in interface AbstractSequence

writeExternal

public void writeExternal(ObjectOutput out)
            throws IOException
Overrides:
writeExternal in interface LList