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 EmptyListEmpty-
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 intboundedHash(int seed, int limit)Calculate a hash code for this object.static Pairchain1(Pair old, Object arg1)Utility function used by compiler when inlining `list'.static Pairchain4(Pair old, Object arg1, Object arg2, Object arg3, Object arg4)Utility function used by compiler when inlining `list'.static ObjectcheckNonList(Object rest)Helper to protect against pathological LLists (neithr Pair nor Empty).intcompareTo(Object obj)voidconsume(Consumer out)static ObjectconsX(Object[] args)SRFI-1's cons* and Common Lisp's list* function.intcreatePos(int index, boolean isAfter)Generate a position at a given index.intcreateRelativePos(int pos, int delta, boolean isAfter)booleanequals(Object obj)Objectget(int index)See java.util.List.SeqPositiongetIterator(int index)ObjectgetPosNext(int ipos)Get the element following the specified position.ObjectgetPosPrevious(int ipos)Get the element before the specified position.inthashCode()booleanhasNext(int ipos)booleanisEmpty()True is this sequence contains no elements.static intlength(Object arg)static Pairlist1(Object arg1)static Pairlist2(Object arg1, Object arg2)static Pairlist3(Object arg1, Object arg2, Object arg3)static Pairlist4(Object arg1, Object arg2, Object arg3, Object arg4)static intlistLength(Object obj, boolean allowOtherSequence)A safe function to count the length of a list.static LListmakeList(Object[] vals, int offset)static LListmakeList(Object[] vals, int offset, int length)static LListmakeList(List vals)intnextPos(int ipos)Return the next position following the argument.voidreadExternal(ObjectInput in)ObjectreadResolve()static LListreverseInPlace(Object list)Reverse a list in place, by modifying the cdr fields.protected voidsetPosNext(int ipos, Object value)protected voidsetPosPrevious(int ipos, Object value)intsize()See java.util.List.StringtoString()voidwriteExternal(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:
equalsin interfaceCollection<Object>- Specified by:
equalsin interfaceList<Object>- Overrides:
equalsin classAbstractSequence<Object>
-
compareTo
public int compareTo(Object obj)
- Specified by:
compareToin interfaceComparable
-
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.
-
getIterator
public SeqPosition getIterator(int index)
- Overrides:
getIteratorin classAbstractSequence<Object>
-
createPos
public int createPos(int index, boolean isAfter)Description copied from class:AbstractSequenceGenerate a position at a given index. The result is a position cookie that must be free'd with releasePos.- Overrides:
createPosin 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:
createRelativePosin classAbstractSequence<Object>
-
hasNext
public boolean hasNext(int ipos)
- Overrides:
hasNextin classAbstractSequence<Object>
-
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.- Overrides:
nextPosin classAbstractSequence<Object>
-
getPosNext
public Object getPosNext(int ipos)
Description copied from class:AbstractSequenceGet the element following the specified position.- Overrides:
getPosNextin 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:AbstractSequenceGet the element before the specified position.- Overrides:
getPosPreviousin 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:
setPosNextin classAbstractSequence<Object>
-
setPosPrevious
protected void setPosPrevious(int ipos, Object value)- Overrides:
setPosPreviousin classAbstractSequence<Object>
-
length
public static final int length(Object arg)
-
boundedHash
public int boundedHash(int seed, int limit)Description copied from interface:BoundedHashableCalculate a hash code for this object.- Specified by:
boundedHashin interfaceBoundedHashable- Overrides:
boundedHashin 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:
hashCodein interfaceCollection<Object>- Specified by:
hashCodein interfaceList<Object>- Overrides:
hashCodein classAbstractSequence<Object>
-
consume
public void consume(Consumer out)
- Specified by:
consumein interfaceConsumable- Overrides:
consumein classAbstractSequence<Object>
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternalin 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:
toStringin classAbstractSequence<Object>
-
-