Package gnu.lists
Class Pair
- java.lang.Object
-
- gnu.lists.AbstractSequence<E>
-
- gnu.lists.ExtSequence<java.lang.Object>
-
- gnu.lists.LList
-
- gnu.lists.Pair
-
- All Implemented Interfaces:
BoundedHashable,Consumable,Sequence<java.lang.Object>,java.io.Externalizable,java.io.Serializable,java.lang.Comparable,java.lang.Iterable<java.lang.Object>,java.util.Collection<java.lang.Object>,java.util.List<java.lang.Object>
- Direct Known Subclasses:
ImmutablePair,Translator.FormStack
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 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 java.lang.Objectcarprotected java.lang.Objectcdrstatic PairincompleteListMarkerA 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 intcompareTo(Pair pair1, Pair pair2)intcompareTo(java.lang.Object obj)static booleanequals(Pair pair1, Pair pair2)booleanequals(java.lang.Object obj)java.lang.Objectget(int index)See java.util.List.java.lang.ObjectgetCar()java.lang.ObjectgetCdr()java.lang.ObjectgetPosNext(int ipos)Get the element following the specified position.java.lang.ObjectgetPosPrevious(int ipos)Get the element before the specified position.booleanhasNext(int ipos)booleanisEmpty()True is this sequence contains no elements.PairlastPair()intlength()static Pairmake(java.lang.Object car, java.lang.Object cdr)intnextPos(int ipos)Return the next position following the argument.voidreadExternal(java.io.ObjectInput in)java.lang.ObjectreadResolve()Needed to override readResolve in LList.voidsetCar(java.lang.Object car)voidsetCarBackdoor(java.lang.Object car)May go away soon.voidsetCdr(java.lang.Object cdr)voidsetCdrBackdoor(java.lang.Object cdr)intsize()See java.util.List.java.lang.Object[]toArray()java.lang.Object[]toArray(java.lang.Object[] arr)voidwriteExternal(java.io.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
-
-
-
-
Field Detail
-
car
protected java.lang.Object car
-
cdr
protected java.lang.Object cdr
-
incompleteListMarker
public static final Pair incompleteListMarker
A special pair used to indicate incomplete input.
-
-
Method Detail
-
getCar
public java.lang.Object getCar()
-
getCdr
public java.lang.Object getCdr()
-
setCar
public void setCar(java.lang.Object car)
-
setCdr
public void setCdr(java.lang.Object cdr)
-
setCarBackdoor
public void setCarBackdoor(java.lang.Object car)
May go away soon.
-
setCdrBackdoor
public void setCdrBackdoor(java.lang.Object cdr)
-
size
public int size()
Description copied from interface:SequenceSee java.util.List.
-
isEmpty
public boolean isEmpty()
Description copied from interface:SequenceTrue is this sequence contains no elements.
-
length
public int length()
-
nextPos
public int nextPos(int ipos)
Description copied from class:AbstractSequenceReturn 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 java.lang.Object getPosNext(int ipos)
Description copied from class:AbstractSequenceGet the element following the specified position.- Overrides:
getPosNextin 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 java.lang.Object getPosPrevious(int ipos)
Description copied from class:AbstractSequenceGet the element before the specified position.- Overrides:
getPosPreviousin 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(java.lang.Object obj)
-
get
public java.lang.Object get(int index)
Description copied from interface:SequenceSee java.util.List.
-
equals
public boolean equals(java.lang.Object obj)
-
make
public static Pair make(java.lang.Object car, java.lang.Object cdr)
-
toArray
public java.lang.Object[] toArray()
- Specified by:
toArrayin interfacejava.util.Collection<java.lang.Object>- Specified by:
toArrayin interfacejava.util.List<java.lang.Object>- Overrides:
toArrayin classAbstractSequence<java.lang.Object>
-
toArray
public java.lang.Object[] toArray(java.lang.Object[] arr)
- Specified by:
toArrayin interfacejava.util.Collection<java.lang.Object>- Specified by:
toArrayin interfacejava.util.List<java.lang.Object>- Overrides:
toArrayin classAbstractSequence<java.lang.Object>
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException- Specified by:
writeExternalin interfacejava.io.Externalizable- Overrides:
writeExternalin classLList- Throws:
java.io.IOException
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException- Specified by:
readExternalin interfacejava.io.Externalizable- Overrides:
readExternalin classLList- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
readResolve
public java.lang.Object readResolve() throws java.io.ObjectStreamExceptionNeeded to override readResolve in LList.- Overrides:
readResolvein classLList- Throws:
java.io.ObjectStreamException
-
-