Package gnu.lists
Class AbstractSequence<E>
java.lang.Object
gnu.lists.AbstractSequence<E>
- Direct Known Subclasses:
Arrays.BuiltArray,ExtSequence,IndirectIndexedSeq,IString,Range,SimpleVector,SubSequence,TransformedArray,TreeList,Values
A collection of default methods for implementing sequence-like classes.
Additionally, a sequence may have zero or more attributes, which are
name-value pairs. A sequence may also have a named "type". These
extensions are to support XML functionality - it might be cleaner to
move them to a sub-class of Sequence or some interface.
Many of the protected methods in Sequence (such as nextIndex) are
only intended to be called from SeqPosition or TreePosition, see those.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidSee java.util.List.booleanSee java.util.Collection.booleanaddAll(int index, Collection<? extends E> c) See java.util.Collection.booleanaddAll(Collection<? extends E> c) See java.util.Collection.protected intAdd a value at a specified Pos.protected RuntimeExceptionbadRank(int i) intboundedHash(int seed, int limit) protected voidprotected voidcheckRank(int i) voidclear()intcompare(int ipos1, int ipos2) Compare two positions, and indicate their relative order.static intcompare(AbstractSequence seq1, int pos1, AbstractSequence seq2, int pos2) This is used for the XML concept of "document order".final intcompare(SeqPosition i1, SeqPosition i2) voidvoidbooleanconsumeNext(int ipos, Consumer out) Copy an element specified by a position pair to a Consumer.voidconsumePosRange(int iposStart, int iposEnd, Consumer out) booleanSee java.util.List.booleancontainsAll(Collection<?> c) See java.util.List.intcopyPos(int ipos) Make a copy of a position int.intcreatePos(int index, boolean isAfter) Generate a position at a given index.intcreateRelativePos(int pos, int delta, boolean isAfter) intinteffectiveIndex(int index) inteffectiveIndex(int[] indexes) inteffectiveIndex(int i, int j) inteffectiveIndex(int i, int j, int k, int... rest) final Enumeration<E> elements()intendPos()booleanequals(int ipos1, int ipos2) Compare two positions, and indicate if they are the same position.booleanvoidvoidvoidfillPosRange(int fromPos, int toPos, E value) intfirstAttributePos(int ipos) Like firstChildPos.intfirstChildPos(int ipos) Get position before first child (of the element following position).intfirstChildPos(int ipos, ItemPredicate predicate) protected intfromEndIndex(int ipos) get()get(int i) get(int[] indexes) get(int i, int j) get(int i, int j, int k, int... rest) getAttribute(int index) intbooleangetBooleanRaw(int index) bytegetByteRaw(int index) chargetCharRaw(int index) protected intgetContainingSequenceSize(int ipos) Get the size of the (sub-) sequence containing a given position.doublegetDoubleRaw(int index) intfloatgetFloatRaw(int index) protected intgetIndexDifference(int ipos1, int ipos0) Get offset of (ipos1) relative to (ipos0).intgetInt()intgetInt(int i) intgetInt(int[] indexes) intgetInt(int i, int j) intgetInt(int i, int j, int k, int... rest) intgetIntRaw(int index) final SeqPosition<E, AbstractSequence<E>> getIterator(int index) getIteratorAtPos(int ipos) longgetLongRaw(int index) intgetLowBound(int dim) intgetNextKind(int ipos) getNextTypeName(int ipos) getNextTypeObject(int ipos) getPosNext(int ipos) Get the element following the specified position.getPosPrevious(int ipos) Get the element before the specified position.getRaw(int index) getRowMajor(int index) shortgetShortRaw(int index) intgetSize()intgetSize(int dim) protected booleanfinal booleanSet position before first child (of the element following position).protected booleangotoParent(TreePosition pos) inthashCode()booleanhasNext(int ipos) protected booleanhasPrevious(int ipos) Called by SeqPosition.hasPrevious.intSee java.util.List.protected booleanisAfterPos(int ipos) Tests whether the position has the "isAfter" property.booleanisEmpty()iterator()intSee java.util.List.final ListIterator<E> final ListIterator<E> listIterator(int index) protected intnextIndex(int ipos) Get the offset from the beginning corresponding to a position cookie.final intnextIndex(SeqPosition pos) intnextMatching(int startPos, ItemPredicate type, int endPos, boolean descend) Get next matching child or descendent (ignoring attributes).intnextPos(int ipos) Return the next position following the argument.intparentPos(int ipos) Get position of parent.intpreviousPos(int ipos) Return the previous position following the argument.intrank()protected voidreleasePos(int ipos) Reclaim any resources used by the given position int.remove(int index) booleanbooleanremoveAll(Collection<?> c) voidremovePos(int ipos, int count) Remove one or more elements.protected voidremovePosRange(int ipos0, int ipos1) Remove a range where each end-point is a position in a container.booleanretainAll(Collection<?> c) voidvoidprotected voidprotected voidsetPosNext(int ipos, E value) protected voidsetPosPrevious(int ipos, E value) voidGiven an "effective index", set selected element.intsize()intstableCompare(AbstractSequence other) This is used for the XML concept of "document order".intstartPos()subList(int fromIx, int toIx) subSequence(SeqPosition start, SeqPosition end) subSequencePos(int ipos0, int ipos1) Object[]toArray()<T> T[]toArray(T[] arr) toString()voidtoString(String sep, StringBuffer sbuf) protected RuntimeExceptionunsupported(String text) static RuntimeExceptionunsupportedException(String text)
-
Field Details
-
noInts
public static final int[] noInts
-
-
Constructor Details
-
AbstractSequence
public AbstractSequence()
-
-
Method Details
-
size
public int size() -
getSize
public int getSize() -
isEmpty
public boolean isEmpty() -
rank
public int rank() -
checkRank
protected void checkRank(int i) -
badRank
-
asImmutable
-
get
-
get
-
get
-
get
-
get
-
checkCanWrite
protected void checkCanWrite() -
getRowMajor
-
effectiveIndex
public int effectiveIndex() -
effectiveIndex
public int effectiveIndex(int index) -
effectiveIndex
public int effectiveIndex(int i, int j) -
effectiveIndex
public int effectiveIndex(int i, int j, int k, int... rest) -
effectiveIndex
public int effectiveIndex(int[] indexes) -
getRaw
-
setBuffer
-
setRaw
Given an "effective index", set selected element. -
getBooleanRaw
public boolean getBooleanRaw(int index) -
getCharRaw
public char getCharRaw(int index) -
getByteRaw
public byte getByteRaw(int index) -
getShortRaw
public short getShortRaw(int index) -
getIntRaw
public int getIntRaw(int index) -
getLongRaw
public long getLongRaw(int index) -
getFloatRaw
public float getFloatRaw(int index) -
getDoubleRaw
public double getDoubleRaw(int index) -
getInt
public int getInt() -
getInt
public int getInt(int i) -
getInt
public int getInt(int i, int j) -
getInt
public int getInt(int i, int j, int k, int... rest) -
getInt
public int getInt(int[] indexes) -
set
-
getLowBound
public int getLowBound(int dim) -
getSize
public int getSize(int dim) -
getElementKind
public int getElementKind() -
unsupported
-
unsupportedException
-
set
-
setAt
-
fill
-
fillPosRange
-
fill
-
indexOf
See java.util.List. -
lastIndexOf
See java.util.List. -
nextMatching
Get next matching child or descendent (ignoring attributes).- Parameters:
startPos- starting positiontype- a test (predicate) to apply to selected elementsendPos- stop before endPosdescend- if true do depth-first traversal.- Returns:
- poistion of next match or 0 if none found
-
contains
See java.util.List. -
containsAll
See java.util.List. -
elements
-
getIterator
-
getIterator
-
getIteratorAtPos
-
iterator
-
listIterator
-
listIterator
-
addPos
Add a value at a specified Pos.- Returns:
- the updated Pos, which is after the inserted value..
-
add
See java.util.Collection. -
add
See java.util.List. -
addAll
See java.util.Collection. -
addAll
See java.util.Collection. -
removePos
public void removePos(int ipos, int count) Remove one or more elements.- Parameters:
ipos- position where elements should be removedcount- if non-negative, remove that number of elements following (poses, posNumber); if negative the negative of the number of elements to remove before (poses, posNumber).- Throws:
IndexOutOfBoundsException- if(count >= 0 ? (index < 0 || index + count > size()) : (index + count < 0 || index > size())), whereindex == nextIndex(ipos, xpos).
-
removePosRange
protected void removePosRange(int ipos0, int ipos1) Remove a range where each end-point is a position in a container.- Parameters:
ipos0- start of range, as a poistionipos1- end of range- Throws:
IndexOutOfBoundsException- ifnextIndex(ipos0) > nextIndex(ipos1)ornextIndex(ipos0) < 0ornextIndex(ipos1) > size().
-
remove
-
remove
-
removeAll
-
retainAll
-
clear
public void clear() -
isAfterPos
protected boolean isAfterPos(int ipos) Tests whether the position has the "isAfter" property. I.e. if something is inserted at the position, will the iterator end up being after the new data? -
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.- Parameters:
index- offset from beginning of desired positionisAfter- should the position have the isAfter property- Throws:
IndexOutOfBoundsException- if index is out of bounds
-
createRelativePos
public int createRelativePos(int pos, int delta, boolean isAfter) -
startPos
public int startPos() -
endPos
public int endPos() -
releasePos
protected void releasePos(int ipos) Reclaim any resources used by the given position int.- Parameters:
ipos- the Pos being free'd.
-
copyPos
public int copyPos(int ipos) Make a copy of a position int. For simple positions returns the argument. However, if the positions are magic cookies that are actively managed by the sequence (as opposed to for example a simple index), then making a copy may need to increment a reference count, or maybe allocate a new position cookie. In any case, the new position is initialized to the same offset (and isAfter property) as the original.- Parameters:
ipos- the position being copied.- Returns:
- the new position
-
getIndexDifference
protected int getIndexDifference(int ipos1, int ipos0) Get offset of (ipos1) relative to (ipos0). -
nextIndex
protected int nextIndex(int ipos) Get the offset from the beginning corresponding to a position cookie. -
fromEndIndex
protected int fromEndIndex(int ipos) -
getContainingSequenceSize
protected int getContainingSequenceSize(int ipos) Get the size of the (sub-) sequence containing a given position. Normally the same as size(), but may be different if this Sequence is a tree and the position points at an interior node. -
hasNext
public boolean hasNext(int ipos) -
getNextKind
public int getNextKind(int ipos) -
getNextTypeName
-
getNextTypeObject
-
hasPrevious
protected boolean hasPrevious(int ipos) Called by SeqPosition.hasPrevious. -
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. -
previousPos
public int previousPos(int ipos) Return the previous position following the argument. The new position has the isBefore property. The argument is implicitly released (as in releasePos). Returns -1 if we are already at beginning of file. -
gotoChildrenStart
Set position before first child (of the element following position).- Returns:
- true if there is a child sequence (which might be empty); false if current position is end of sequence or following element is atomic (cannot have children).
-
firstChildPos
public int firstChildPos(int ipos) Get position before first child (of the element following position).- Parameters:
ipos- parent position. It is not released by this method.- Returns:
- non-zero position cookie if there is a child sequence (which might be empty); zero if current position is end of sequence or following element is atomic (cannot have children).
-
firstChildPos
-
firstAttributePos
public int firstAttributePos(int ipos) Like firstChildPos. Problem: Should this stop before we get to children? I think so, but that requires changes to TreeList. -
parentPos
public int parentPos(int ipos) Get position of parent.- Parameters:
ipos- child position. It is not released by this method.- Returns:
- the p os of the parent, or endPos() is there is no known parent.
-
gotoParent
-
getAttributeLength
public int getAttributeLength() -
getAttribute
-
gotoAttributesStart
-
getPosNext
Get the element following the specified position.- 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
Get the element before the specified position.- 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
-
setPosPrevious
-
nextIndex
-
equals
public boolean equals(int ipos1, int ipos2) Compare two positions, and indicate if they are the same position. -
compare
public int compare(int ipos1, int ipos2) Compare two positions, and indicate their relative order. -
compare
-
toArray
-
toArray
public <T> T[] toArray(T[] arr) -
stableCompare
This is used for the XML concept of "document order". -
compare
This is used for the XML concept of "document order". It is overridden in gnu.xml.NodeTree for a more robust implementation. -
hashCode
public int hashCode() -
boundedHash
public int boundedHash(int seed, int limit) -
equals
-
subSequence
-
subSequencePos
-
subList
-
consumeNext
Copy an element specified by a position pair to a Consumer.- Returns:
- if hasNext(ipos).
-
consumePosRange
-
consume
-
consume
-
toString
-
toString
-