Package gnu.lists
Class Pair
- java.lang.Object
-
- gnu.lists.AbstractSequence<E>
-
- gnu.lists.ExtSequence<Object>
-
- gnu.lists.LList
-
- gnu.lists.Pair
-
- All Implemented Interfaces:
BoundedHashable
,Consumable
,Sequence<Object>
,Externalizable
,Serializable
,Comparable
,Iterable<Object>
,Collection<Object>
,List<Object>
- Direct Known Subclasses:
ImmutablePair
,Translator.FormStack
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 points to some other non-list object; this is traditionally callled a "dotted list".- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Object
car
protected Object
cdr
static Pair
incompleteListMarker
A special pair used to indicate incomplete input.-
Fields inherited from class gnu.lists.AbstractSequence
noInts
-
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
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static int
compareTo(Pair pair1, Pair pair2)
int
compareTo(Object obj)
static boolean
equals(Pair pair1, Pair pair2)
boolean
equals(Object obj)
Object
get(int index)
See java.util.List.Object
getCar()
Object
getCdr()
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)
boolean
isEmpty()
True is this sequence contains no elements.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.void
setCar(Object car)
void
setCarBackdoor(Object car)
May go away soon.void
setCdr(Object cdr)
void
setCdrBackdoor(Object cdr)
int
size()
See java.util.List.Object[]
toArray()
Object[]
toArray(Object[] arr)
void
writeExternal(ObjectOutput out)
-
Methods inherited from class gnu.lists.LList
boundedHash, chain1, chain4, checkNonList, consume, consX, createPos, createRelativePos, getIterator, hashCode, length, list1, list2, list3, list4, listLength, 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, asImmutable, badRank, checkCanWrite, checkRank, clear, compare, compare, compare, consume, consumeNext, consumePosRange, contains, containsAll, effectiveIndex, effectiveIndex, effectiveIndex, effectiveIndex, effectiveIndex, elements, endPos, equals, fill, fill, fillPosRange, firstAttributePos, firstChildPos, firstChildPos, fromEndIndex, get, get, get, get, getAttribute, getAttributeLength, getBooleanRaw, getByteRaw, getCharRaw, getContainingSequenceSize, getDoubleRaw, getElementKind, getFloatRaw, getIndexDifference, getInt, getInt, getInt, getInt, getInt, getIntRaw, getIterator, getIteratorAtPos, getLongRaw, getLowBound, getNextKind, getNextTypeName, getNextTypeObject, getRaw, getRowMajor, getShortRaw, getSize, getSize, gotoAttributesStart, gotoChildrenStart, gotoParent, hasPrevious, indexOf, iterator, lastIndexOf, listIterator, listIterator, nextIndex, nextMatching, parentPos, previousPos, rank, remove, remove, removeAll, removePos, removePosRange, retainAll, set, set, setAt, setBuffer, setRaw, 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 java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.List
add, add, addAll, addAll, clear, contains, containsAll, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, replaceAll, retainAll, sort, spliterator, subList
-
-
-
-
Method Detail
-
getCar
public Object getCar()
-
getCdr
public Object getCdr()
-
setCar
public void setCar(Object car)
-
setCdr
public void setCdr(Object cdr)
-
setCarBackdoor
public void setCarBackdoor(Object car)
May go away soon.
-
setCdrBackdoor
public void setCdrBackdoor(Object cdr)
-
size
public int size()
Description copied from interface:Sequence
See java.util.List.
-
isEmpty
public boolean isEmpty()
Description copied from interface:Sequence
True is this sequence contains no elements.
-
length
public int length()
-
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.
-
getPosNext
public Object getPosNext(int ipos)
Description copied from class:AbstractSequence
Get the element following the specified position.- Overrides:
getPosNext
in classLList
- Parameters:
ipos
- the specified position.- Returns:
- the following element, or eofValue if there is none. Called by SeqPosition.getNext. FIXME Should change eof handling so return type can be E.
-
getPosPrevious
public Object getPosPrevious(int ipos)
Description copied from class:AbstractSequence
Get the element before the specified position.- Overrides:
getPosPrevious
in classLList
- Parameters:
ipos
- the specified position.- Returns:
- the following element, or eofValue if there is none. FIXME Should change eof handling so return type can be E.
-
lastPair
public Pair lastPair()
-
compareTo
public int compareTo(Object obj)
- Specified by:
compareTo
in interfaceComparable
- Overrides:
compareTo
in classLList
-
equals
public boolean equals(Object obj)
-
toArray
public Object[] toArray()
- Specified by:
toArray
in interfaceCollection<Object>
- Specified by:
toArray
in interfaceList<Object>
- Overrides:
toArray
in classAbstractSequence<Object>
-
toArray
public Object[] toArray(Object[] arr)
- Specified by:
toArray
in interfaceCollection<Object>
- Specified by:
toArray
in interfaceList<Object>
- Overrides:
toArray
in classAbstractSequence<Object>
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternal
in interfaceExternalizable
- Overrides:
writeExternal
in classLList
- Throws:
IOException
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternal
in interfaceExternalizable
- Overrides:
readExternal
in classLList
- Throws:
IOException
ClassNotFoundException
-
readResolve
public Object readResolve() throws ObjectStreamException
Needed to override readResolve in LList.- Overrides:
readResolve
in classLList
- Throws:
ObjectStreamException
-
-