Package gnu.lists
Class LList
- java.lang.Object
-
- gnu.lists.AbstractSequence<E>
-
- gnu.lists.ExtSequence<Object>
-
- gnu.lists.LList
-
- All Implemented Interfaces:
BoundedHashable
,Consumable
,Sequence<Object>
,Externalizable
,Serializable
,Comparable
,Iterable<Object>
,Collection<Object>
,List<Object>
public class LList extends ExtSequence<Object> implements Sequence<Object>, 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.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static EmptyList
Empty
-
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
-
-
Constructor Summary
Constructors Constructor Description LList()
Do not use - only public for serialization!
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
boundedHash(int seed, int limit)
Calculate a hash code for this object.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)
static Object
consX(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(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.int
hashCode()
boolean
hasNext(int ipos)
boolean
isEmpty()
True is this sequence contains no elements.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 LList
makeList(Object[] vals, int offset)
static LList
makeList(Object[] vals, int offset, int length)
static LList
makeList(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, 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, toArray, toArray, 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, toArray, toArray
-
-
-
-
Field Detail
-
Empty
public static final EmptyList Empty
-
-
Method Detail
-
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 measureallowOtherSequence
- if a non-List Sequence is seen, allow that- Returns:
- the length, or -1 for a circular list, or -2 for a dotted list
-
equals
public boolean equals(Object obj)
- Specified by:
equals
in interfaceCollection<Object>
- Specified by:
equals
in interfaceList<Object>
- Overrides:
equals
in classAbstractSequence<Object>
-
compareTo
public int compareTo(Object obj)
- Specified by:
compareTo
in interfaceComparable
-
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.
-
getIterator
public SeqPosition getIterator(int index)
- Overrides:
getIterator
in classAbstractSequence<Object>
-
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.- Overrides:
createPos
in classAbstractSequence<Object>
- Parameters:
index
- offset from beginning of desired positionisAfter
- should the position have the isAfter property
-
createRelativePos
public int createRelativePos(int pos, int delta, boolean isAfter)
- Overrides:
createRelativePos
in classAbstractSequence<Object>
-
hasNext
public boolean hasNext(int ipos)
- Overrides:
hasNext
in classAbstractSequence<Object>
-
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 classAbstractSequence<Object>
-
getPosNext
public Object getPosNext(int ipos)
Description copied from class:AbstractSequence
Get the element following the specified position.- Overrides:
getPosNext
in classAbstractSequence<Object>
- 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 classAbstractSequence<Object>
- 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.
-
setPosNext
protected void setPosNext(int ipos, Object value)
- Overrides:
setPosNext
in classAbstractSequence<Object>
-
setPosPrevious
protected void setPosPrevious(int ipos, Object value)
- Overrides:
setPosPrevious
in classAbstractSequence<Object>
-
length
public static final int length(Object arg)
-
boundedHash
public int boundedHash(int seed, int limit)
Description copied from interface:BoundedHashable
Calculate a hash code for this object.- Specified by:
boundedHash
in interfaceBoundedHashable
- Overrides:
boundedHash
in classAbstractSequence<Object>
- Parameters:
seed
- The seed is an initial value, or the accumulated hash code from previous elements in a containing object. Using zero as the seed is fine.limit
- A limit on the number of sub-elements whose hash we should calculate. This guards against cycles. Any recursive calls should be done with a smaller value of limit, and no recursive calls must be done when the limit is zero.- Returns:
- A well-dispersed hash code.
The result is not compatible with
Object#hashCode
.
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfaceCollection<Object>
- Specified by:
hashCode
in interfaceList<Object>
- Overrides:
hashCode
in classAbstractSequence<Object>
-
consume
public void consume(Consumer out)
- Specified by:
consume
in interfaceConsumable
- Overrides:
consume
in classAbstractSequence<Object>
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
ClassNotFoundException
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
readResolve
public Object readResolve() throws ObjectStreamException
- Throws:
ObjectStreamException
-
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'.
-
reverseInPlace
public static LList reverseInPlace(Object list)
Reverse a list in place, by modifying the cdr fields.
-
toString
public String toString()
- Overrides:
toString
in classAbstractSequence<Object>
-
-