Interface IPositionHolder<T,P extends IPositionHolder<T,P>>
-
- All Superinterfaces:
IPositionListener
- All Known Subinterfaces:
IPosition<T,P>
- All Known Implementing Classes:
IPositionBase
,Position
public interface IPositionHolder<T,P extends IPositionHolder<T,P>> extends IPositionListener
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.Iterable<P>
backwards()
Iterable for this position and all previous positions in decreasing index ordervoid
detachListener()
Tells listener to remove itself from parent NOTE: used as optimization in iterators which are guaranteed not to have any other references to their position element.boolean
equals(java.lang.Object other)
Listeners should not change hashCode() or equals() from their default implementation where the instance is only equal to itself.java.lang.Iterable<P>
forwards()
iterable for this position and all following positions in increasing index orderPositionAnchor
getAnchor()
Position Anchor for this positionint
getIndex()
FIX: allow getIndex(offset) to return -1int
hashCode()
Listeners should not change hashCode() or equals() from their default implementation where the instance is only equal to itself.boolean
hasNext()
boolean
hasPrevious()
boolean
isDetached()
boolean
isValid()
boolean
isValidElement()
P
next()
Get next index position relative to current, returns next position if it exists even when this position is not validjava.lang.Iterable<P>
nextForwards()
Iterator for all following positions, excluding this position in increasing index orderint
nextIndex()
Returns the index of the element that would be returned by a subsequent call tonext()
.P
nextOrNull()
Return valid next position, with the same position anchor as this position, or null if does not exist.P
previous()
Get previous index position relative to current, returns previous index if it exists even when this position is not validjava.lang.Iterable<P>
previousBackwards()
iterable for all previous positions, excluding this position in decreasing index orderint
previousIndex()
Returns the index of the element that would be returned by a subsequent call toprevious()
.P
previousOrNull()
Return valid previous position, with the same position anchor as this position, or null if does not exist.T
remove()
void
setDetached()
Tells the listener it has been detached by its parent list NOTE: used as optimization in position list frames to detach any positions which have not been unframed()void
unframed()
Mark this position as used outside the iteration frame in which it was created.P
withAnchor(PositionAnchor anchor)
Get a new position with requested anchor from this position-
Methods inherited from interface com.vladsch.flexmark.experimental.util.collection.iteration.IPositionListener
deleted, inserted
-
-
-
-
Method Detail
-
forwards
java.lang.Iterable<P> forwards()
iterable for this position and all following positions in increasing index order- Returns:
- iterable whose first element is this position, iteration proceeds toward index list.size()
-
nextForwards
java.lang.Iterable<P> nextForwards()
Iterator for all following positions, excluding this position in increasing index order- Returns:
- iterable whose first element is one after this position, iteration proceeds toward index list.size()
-
backwards
java.lang.Iterable<P> backwards()
Iterable for this position and all previous positions in decreasing index order- Returns:
- iterable whose first element is this position, iteration proceeds toward index 0
-
previousBackwards
java.lang.Iterable<P> previousBackwards()
iterable for all previous positions, excluding this position in decreasing index order- Returns:
- iterable whose first element is previous to this position, iteration proceeds toward index 0
-
getIndex
int getIndex()
FIX: allow getIndex(offset) to return -1- Returns:
- absolute index in list, even when this position does not refer to a valid element it will always be [-1, list.size()] if it is referring to a valid element then the returned range will be [0, list.size()-1]
-
detachListener
void detachListener()
Tells listener to remove itself from parent NOTE: used as optimization in iterators which are guaranteed not to have any other references to their position element.Do not otherwise use this because this position will stop having the list modification updates and will throw
IllegalStateException
on any attempt to use any methods of this position other thanisDetached()
-
isDetached
boolean isDetached()
-
setDetached
void setDetached()
Tells the listener it has been detached by its parent list NOTE: used as optimization in position list frames to detach any positions which have not been unframed()
-
unframed
void unframed()
Mark this position as used outside the iteration frame in which it was created. It allows positions to not be detached when the frame is closed.
-
getAnchor
@NotNull PositionAnchor getAnchor()
Position Anchor for this position- Returns:
- position anchor
-
withAnchor
@NotNull P withAnchor(@NotNull PositionAnchor anchor)
Get a new position with requested anchor from this positionCURRENT - position represents the element and if deleted will be invalidated, if inserting at or before index then will advance to keep position of element
NEXT - position represents the next element
PREVIOUS - position represents the previous element
- Parameters:
anchor
- desired anchor position- Returns:
- new position with requested or this if there is no anchor change
-
previous
P previous()
Get previous index position relative to current, returns previous index if it exists even when this position is not valid- Returns:
- previous valid position relative to this position, with the same position anchor as this position
throws
IndexOutOfBoundsException
if there is no elements before current position
-
previousOrNull
@Nullable P previousOrNull()
Return valid previous position, with the same position anchor as this position, or null if does not exist. Does not throw exceptions- Returns:
- previous position or null
-
next
P next()
Get next index position relative to current, returns next position if it exists even when this position is not valid- Returns:
- previous valid position relative to this position, with the same position anchor as this position
throws
IndexOutOfBoundsException
if there is no elements before current position
-
nextOrNull
@Nullable P nextOrNull()
Return valid next position, with the same position anchor as this position, or null if does not exist. Does not throw exceptions- Returns:
- next position or null
-
nextIndex
int nextIndex()
Returns the index of the element that would be returned by a subsequent call tonext()
. (Returns list size if the list iterator is at the end of the list.)- Returns:
- the index of the element that would be returned by a
subsequent call to
next
, or list size if the list iterator is at the end of the list
-
previousIndex
int previousIndex()
Returns the index of the element that would be returned by a subsequent call toprevious()
. (Returns -1 if the list iterator is at the beginning of the list.)- Returns:
- the index of the element that would be returned by a
subsequent call to
previous
, or -1 if the list iterator is at the beginning of the list
-
isValid
boolean isValid()
- Returns:
- true if this position was not invalidated by deleting the element at index
-
hasPrevious
boolean hasPrevious()
- Returns:
- true if getPreviousIndex() will return a value, false if
previous()
will throw an exception
-
hasNext
boolean hasNext()
- Returns:
- true if getNextIndex() will return a value, false if
next()
will throw an exception
-
isValidElement
boolean isValidElement()
- Returns:
- true if this position represents a valid element in the list, ie. isValid() is true and index is at or before last element in list
-
remove
T remove()
- Returns:
- removed current element, throws IllegalStateException if current index is not valid or after last element of list
-
hashCode
int hashCode()
Listeners should not change hashCode() or equals() from their default implementation where the instance is only equal to itself. Otherwise, a new instance can remove an old one from the weak hash map used to hold listener instances.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- hash
-
equals
boolean equals(java.lang.Object other)
Listeners should not change hashCode() or equals() from their default implementation where the instance is only equal to itself. Otherwise, a new instance can remove an old one from the weak hash map used to hold listener instances.- Overrides:
equals
in classjava.lang.Object
- Returns:
- hash
-
-