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 Objectcarprotected 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(Object obj)static booleanequals(Pair pair1, Pair pair2)booleanequals(Object obj)Objectget(int index)See java.util.List.ObjectgetCar()ObjectgetCdr()ObjectgetPosNext(int ipos)Get the element following the specified position.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(Object car, Object cdr)intnextPos(int ipos)Return the next position following the argument.voidreadExternal(ObjectInput in)ObjectreadResolve()Needed to override readResolve in LList.voidsetCar(Object car)voidsetCarBackdoor(Object car)May go away soon.voidsetCdr(Object cdr)voidsetCdrBackdoor(Object cdr)intsize()See java.util.List.Object[]toArray()Object[]toArray(Object[] arr)voidwriteExternal(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: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 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 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(Object obj)
- Specified by:
compareToin interfaceComparable- Overrides:
compareToin classLList
-
equals
public boolean equals(Object obj)
-
toArray
public Object[] toArray()
- Specified by:
toArrayin interfaceCollection<Object>- Specified by:
toArrayin interfaceList<Object>- Overrides:
toArrayin classAbstractSequence<Object>
-
toArray
public Object[] toArray(Object[] arr)
- Specified by:
toArrayin interfaceCollection<Object>- Specified by:
toArrayin interfaceList<Object>- Overrides:
toArrayin classAbstractSequence<Object>
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternalin interfaceExternalizable- Overrides:
writeExternalin classLList- Throws:
IOException
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternalin interfaceExternalizable- Overrides:
readExternalin classLList- Throws:
IOExceptionClassNotFoundException
-
readResolve
public Object readResolve() throws ObjectStreamException
Needed to override readResolve in LList.- Overrides:
readResolvein classLList- Throws:
ObjectStreamException
-
-