gnu.lists
Class LList

java.lang.Object
  extended by gnu.lists.AbstractSequence
      extended by gnu.lists.ExtSequence
          extended by gnu.lists.LList
All Implemented Interfaces:
Consumable, Sequence, java.io.Externalizable, java.io.Serializable, java.lang.Comparable, java.lang.Iterable, java.util.Collection, java.util.List
Direct Known Subclasses:
Pair

public class LList
extends ExtSequence
implements Sequence, java.io.Externalizable, java.lang.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.

See Also:
Serialized Form

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, 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
 
Constructor Summary
LList()
          Do not use - only public for serialization!
 
Method Summary
static Pair chain1(Pair old, java.lang.Object arg1)
          Utility function used by compiler when inlining `list'.
static Pair chain4(Pair old, java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4)
          Utility function used by compiler when inlining `list'.
static java.lang.Object checkNonList(java.lang.Object rest)
          Helper to protect against pathological LLists (neithr Pair nor Empty).
 int compareTo(java.lang.Object obj)
           
 void consume(Consumer out)
           
static java.lang.Object consX(java.lang.Object[] args)
          SRFI-1's cons* and Common Lisp's list* function.
 int createPos(int index, boolean isAfter)
          Generate a position at a given index.
 int createRelativePos(int pos, int delta, boolean isAfter)
           
 boolean equals(java.lang.Object obj)
           
 java.lang.Object get(int index)
          See java.util.List.
 SeqPosition getIterator(int index)
           
 java.lang.Object getPosNext(int ipos)
          Get the element following the specified position.
 java.lang.Object getPosPrevious(int ipos)
          Get the element before the specified position.
 boolean hasNext(int ipos)
           
 boolean isEmpty()
          True is this sequence contains no elements.
static int length(java.lang.Object arg)
           
static Pair list1(java.lang.Object arg1)
           
static Pair list2(java.lang.Object arg1, java.lang.Object arg2)
           
static Pair list3(java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3)
           
static Pair list4(java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3, java.lang.Object arg4)
           
static int listLength(java.lang.Object obj, boolean allowOtherSequence)
          A safe function to count the length of a list.
static java.lang.Object listTail(java.lang.Object list, int count)
           
static LList makeList(java.util.List vals)
           
static LList makeList(java.lang.Object[] vals, int offset)
           
static LList makeList(java.lang.Object[] vals, int offset, int length)
           
 int nextPos(int ipos)
          Return the next position following the argument.
 void readExternal(java.io.ObjectInput in)
           
 java.lang.Object readResolve()
           
static LList reverseInPlace(java.lang.Object list)
          Reverse a list in place, by modifying the cdr fields.
protected  void setPosNext(int ipos, java.lang.Object value)
           
protected  void setPosPrevious(int ipos, java.lang.Object value)
           
 int size()
          See java.util.List.
 java.lang.String toString()
           
 void writeExternal(java.io.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, clear, compare, compare, compare, consumeNext, consumePosRange, contains, containsAll, elements, endPos, equals, fill, fill, fillPosRange, firstAttributePos, firstChildPos, firstChildPos, fromEndIndex, get, getAttribute, getAttributeLength, getContainingSequenceSize, getEffectiveIndex, getIndexDifference, getIterator, getIteratorAtPos, getLowBound, getNextKind, getNextTypeName, getNextTypeObject, getSize, gotoAttributesStart, gotoChildrenStart, gotoParent, hashCode, hasPrevious, indexOf, iterator, lastIndexOf, listIterator, listIterator, nextIndex, nextMatching, parentPos, previousPos, rank, remove, remove, removeAll, removePos, removePosRange, retainAll, set, set, stableCompare, startPos, subList, subSequence, subSequencePos, toArray, toArray, toString, unsupported, unsupportedException
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface gnu.lists.Sequence
elements, fill, set
 
Methods inherited from interface java.util.List
add, add, addAll, addAll, clear, contains, containsAll, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, retainAll, subList, toArray, toArray
 

Field Detail

Empty

public static final LList Empty
Constructor Detail

LList

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

Method Detail

listLength

public static int listLength(java.lang.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

equals

public boolean equals(java.lang.Object obj)
Specified by:
equals in interface java.util.Collection
Specified by:
equals in interface java.util.List
Overrides:
equals in class AbstractSequence

compareTo

public int compareTo(java.lang.Object obj)
Specified by:
compareTo in interface java.lang.Comparable

size

public int size()
Description copied from class: AbstractSequence
See java.util.List.

Specified by:
size in interface Sequence
Specified by:
size in interface java.util.Collection
Specified by:
size in interface java.util.List
Specified by:
size in class AbstractSequence

isEmpty

public boolean isEmpty()
Description copied from interface: Sequence
True is this sequence contains no elements.

Specified by:
isEmpty in interface Sequence
Specified by:
isEmpty in interface java.util.Collection
Specified by:
isEmpty in interface java.util.List
Overrides:
isEmpty in class AbstractSequence

getIterator

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

createPos

public int createPos(int index,
                     boolean isAfter)
Description copied from class: AbstractSequence
Generate a position at a given index. The result is a position cookie that must be free'd with releasePos.

Specified by:
createPos in class 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 class AbstractSequence

hasNext

public boolean hasNext(int ipos)
Overrides:
hasNext in class AbstractSequence

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.

Overrides:
nextPos in class AbstractSequence

getPosNext

public java.lang.Object getPosNext(int ipos)
Description copied from class: AbstractSequence
Get the element following the specified position.

Overrides:
getPosNext in class AbstractSequence
Parameters:
ipos - the specified position.
Returns:
the following element, or eofValue if there is none. Called by SeqPosition.getNext.

getPosPrevious

public java.lang.Object getPosPrevious(int ipos)
Description copied from class: AbstractSequence
Get the element before the specified position.

Overrides:
getPosPrevious in class AbstractSequence
Parameters:
ipos - the specified position.
Returns:
the following element, or eofValue if there is none.

setPosNext

protected void setPosNext(int ipos,
                          java.lang.Object value)
Overrides:
setPosNext in class AbstractSequence

setPosPrevious

protected void setPosPrevious(int ipos,
                              java.lang.Object value)
Overrides:
setPosPrevious in class AbstractSequence

get

public java.lang.Object get(int index)
Description copied from class: AbstractSequence
See java.util.List.

Specified by:
get in interface Sequence
Specified by:
get in interface java.util.List
Specified by:
get in class AbstractSequence

length

public static final int length(java.lang.Object arg)

makeList

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

makeList

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

makeList

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

consume

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

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException
java.lang.ClassNotFoundException

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException

readResolve

public java.lang.Object readResolve()
                             throws java.io.ObjectStreamException
Throws:
java.io.ObjectStreamException

list1

public static Pair list1(java.lang.Object arg1)

list2

public static Pair list2(java.lang.Object arg1,
                         java.lang.Object arg2)

list3

public static Pair list3(java.lang.Object arg1,
                         java.lang.Object arg2,
                         java.lang.Object arg3)

list4

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

chain1

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


chain4

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


reverseInPlace

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


listTail

public static java.lang.Object listTail(java.lang.Object list,
                                        int count)

consX

public static java.lang.Object consX(java.lang.Object[] args)
SRFI-1's cons* and Common Lisp's list* function.


toString

public java.lang.String toString()
Overrides:
toString in class AbstractSequence

checkNonList

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