gnu.lists

Class LList

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

public class LList
extends ExtSequence
implements Sequence, Externalizable, Comparable

Semi-abstract class for traditions Lisp-style lists. A list is implemented as a chain of Pair objects, where the 'car' field of the Pair points to a data element, and the 'cdr' field points to the next Pair. (The names 'car' and 'cdr' are historical; they refer to hardware on machines form the 60's.) Includes singleton static Empty, and the Pair sub-class.

Field Summary

static 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

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

Method Summary

static Pair
chain1(Pair old, Object arg1)
Utility function used by compiler when inlining `list'.
static Pair
chain4(Pair old, Object arg1, Object arg2, Object arg3, Object arg4)
Utility function used by compiler when inlining `list'.
static Object
checkNonList(Object rest)
Helper to protect against pathological LLists (neithr Pair nor Empty).
int
compareTo(Object obj)
void
consume(Consumer out)
int
createPos(int index, boolean isAfter)
Generate a position at a given index.
int
createRelativePos(int pos, int delta, boolean isAfter)
boolean
equals(Object obj)
Object
get(int index)
See java.util.List.
SeqPosition
getIterator(int index)
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()
static int
length(Object arg)
static Pair
list1(Object arg1)
static Pair
list2(Object arg1, Object arg2)
static Pair
list3(Object arg1, Object arg2, Object arg3)
static Pair
list4(Object arg1, Object arg2, Object arg3, Object arg4)
static int
listLength(Object obj, boolean allowOtherSequence)
A safe function to count the length of a list.
static Object
listTail(Object list, int count)
static LList
makeList(Object[] vals, int offset)
static LList
makeList(Object[] vals, int offset, int length)
static LList
makeList(java.util.List vals)
int
nextPos(int ipos)
Return the next position following the argument.
void
readExternal(ObjectInput in)
Object
readResolve()
static LList
reverseInPlace(Object list)
Reverse a list in place, by modifying the cdr fields.
protected void
setPosNext(int ipos, Object value)
protected void
setPosPrevious(int ipos, Object value)
int
size()
See java.util.List.
String
toString()
void
writeExternal(ObjectOutput out)

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

Empty

public static final LList Empty

Constructor Details

LList

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

Method Details

chain1

public static Pair chain1(Pair old,
                          Object arg1)
Utility function used by compiler when inlining `list'.

chain4

public static Pair chain4(Pair old,
                          Object arg1,
                          Object arg2,
                          Object arg3,
                          Object arg4)
Utility function used by compiler when inlining `list'.

checkNonList

public static Object checkNonList(Object rest)
Helper to protect against pathological LLists (neithr Pair nor Empty).

compareTo

public int compareTo(Object obj)

consume

public void consume(Consumer out)
Specified by:
consume in interface Consumable
Overrides:
consume in interface AbstractSequence

createPos

public int createPos(int index,
                     boolean isAfter)
Generate a position at a given index. The result is a position cookie that must be free'd with releasePos.
Overrides:
createPos in interface AbstractSequence
Parameters:
index - offset from beginning of desired position
isAfter - should the position have the isAfter property

createRelativePos

public int createRelativePos(int pos,
                             int delta,
                             boolean isAfter)
Overrides:
createRelativePos in interface AbstractSequence

equals

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

get

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

getIterator

public SeqPosition getIterator(int index)
Overrides:
getIterator in interface AbstractSequence

getPosNext

public Object getPosNext(int ipos)
Get the element following the specified position.
Overrides:
getPosNext in interface AbstractSequence
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 AbstractSequence
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 AbstractSequence

isEmpty

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

length

public static final int length(Object arg)

list1

public static Pair list1(Object arg1)

list2

public static Pair list2(Object arg1,
                         Object arg2)

list3

public static Pair list3(Object arg1,
                         Object arg2,
                         Object arg3)

list4

public static Pair list4(Object arg1,
                         Object arg2,
                         Object arg3,
                         Object arg4)

listLength

public static int listLength(Object obj,
                             boolean allowOtherSequence)
A safe function to count the length of a list.
Parameters:
obj - the putative list to measure
allowOtherSequence - if a non-List Sequence is seen, allow that
Returns:
the length, or -1 for a circular list, or -2 for an improper list

listTail

public static Object listTail(Object list,
                              int count)

makeList

public static LList makeList(Object[] vals,
                             int offset)

makeList

public static LList makeList(Object[] vals,
                             int offset,
                             int length)

makeList

public static LList makeList(java.util.List vals)

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 AbstractSequence

readExternal

public void readExternal(ObjectInput in)
            throws IOException,
                   ClassNotFoundException

readResolve

public Object readResolve()
            throws ObjectStreamException

reverseInPlace

public static LList reverseInPlace(Object list)
Reverse a list in place, by modifying the cdr fields.

setPosNext

protected void setPosNext(int ipos,
                          Object value)
Overrides:
setPosNext in interface AbstractSequence

setPosPrevious

protected void setPosPrevious(int ipos,
                              Object value)
Overrides:
setPosPrevious in interface AbstractSequence

size

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

toString

public String toString()
Overrides:
toString in interface AbstractSequence

writeExternal

public void writeExternal(ObjectOutput out)
            throws IOException