E - the class of the elements to be iterated over.public static final class CyclicArrayList.CyclicArrayIterator<E> extends Object implements CyclicIterator<E>
CyclicList.
CyclicIterator corresponds with CyclicLists
as Iterators or ListIterators does
with Lists.
Nevertheless, CyclicIterator
does not implement java.util.Iterator.CyclicList| Modifier and Type | Field and Description |
|---|---|
private CyclicArrayList<E> |
cal |
private CyclicArrayList.StateIter |
calledLast
Indicates the last method invoked.
|
private int |
index
A non-negative index which points,
modulo
list.size()-1,
to the 0,... |
private int |
startIndex
Points to the beginning of this cyclic list:
this.hasPrev() == false
iff index == startIndex. |
| Constructor and Description |
|---|
CyclicArrayIterator(CyclicArrayList<E> cal,
CyclicArrayList.CyclicArrayIterator<E> iter)
Creates a fresh
CyclicPtIterator
with the same list and the same pointer
as the CyclicPtIterator given. |
CyclicArrayIterator(CyclicArrayList<E> cal,
int index)
Creates a new
CyclicIterator
for the given list,
pointing to the element with the position given. |
| Modifier and Type | Method and Description |
|---|---|
void |
add(E obj)
Inserts the specified element into the cyclic list.
|
void |
addAll(List<? extends E> addList)
Inserts the specified list into the underlying cyclic list.
|
double |
dist(CyclicIterator<E> other) |
boolean |
equals(Object other)
Returns whether
other
is also an instance of CyclicIterator
and, if so, whether the underlying list and the indices coincide. |
CyclicList<E> |
getCyclicList()
Returns the
CyclicList this iterator points to. |
int |
getFirstIndex()
Returns the cursor of this iterator
immediately after it has been created
(if not modified since then which is currently not possible.).
|
int |
getIndex()
Returns the current index of this iterator.
|
int |
getNextIndexOf(E obj)
Returns the (non-negative) index
of the next object returned by
next
which equals the given one, if possible;
otherwise returns -1. |
int |
hashCode() |
boolean |
hasNext()
Returns whether a subsequent call to
next()
would return an element rather than throwing an exception. |
boolean |
hasPrev()
Returns whether a subsequent call to
previous()
does not throw an exception. |
E |
next()
Returns the next element in the interation.
|
E |
previous()
Returns the previous element in the cyclic list.
|
void |
refresh()
Reinitializes this iterator without changing the cursor
(i.e. modulo
list.size())
but such that all elements of the corresponding cyclic list
may be accessed successively through next(). |
void |
remove()
Removes from the underlying
CyclicList
the last element returned by the iterator. |
boolean |
retEquals(CyclicIterator<?> other)
Returns whether the two cyclic iterators given
return the same elements in the same order
if method
next() is invoked sequentially. |
void |
set(E obj)
Replaces the last element
returned by
next or previous
with the specified element (optional operation). |
void |
setIndex(int index)
Sets the pointer to the given index modulo the length of the list.
|
String |
toString()
Returns a string representation consisting of
the cyclic list corresponding with this iterator .
|
clone, finalize, getClass, notify, notifyAll, wait, wait, waitforEachRemainingprivate CyclicArrayList.StateIter calledLast
refresh()private int index
list.size()-1,
to the 0,...,list.size()-1th element
of list
provided CyclicArrayList.list is not empty;
if it is empty, index == -1.private int startIndex
this.hasPrev() == false
iff index == startIndex.
It also determines the end of this list implicitly:
this.hasNext() == false
iff this.index < this.startIndex+this.list.size().
This is true also for CyclicArrayList.list.isEmpty().private CyclicArrayList<E> cal
public CyclicArrayIterator(CyclicArrayList<E> cal, int index)
CyclicIterator
for the given list,
pointing to the element with the position given.
This position is modulo list.size()
and may also be negative.
Note that this list may be empty
(in which case the indices are -1)
but by construction it may not be null.
index - an index modulo list.size(),
provided list is not empty.
In the latter case, index is ignoredpublic CyclicArrayIterator(CyclicArrayList<E> cal, CyclicArrayList.CyclicArrayIterator<E> iter)
CyclicPtIterator
with the same list and the same pointer
as the CyclicPtIterator given.
An iterator is called "fresh" if it delivers all elements of its list. Equivalently, it is called fresh, if after having created it, no getNext-method has been invoked.
iter - some CyclicPtItererator.public int getFirstIndex()
CyclicIteratorgetFirstIndex in interface CyclicIterator<E>CyclicList.cyclicIterator(int)public void refresh()
list.size())
but such that all elements of the corresponding cyclic list
may be accessed successively through next().
On the other hand, previous() throws an exception.refresh in interface CyclicIterator<E>public void setIndex(int index)
setIndex in interface CyclicIterator<E>index - an int
representing a pointer on the underlying list.
This may also be negative.public int getIndex()
getIndex in interface CyclicIterator<E>int value
public CyclicList<E> getCyclicList()
CyclicList this iterator points to.getCyclicList in interface CyclicIterator<E>CyclicList this iterator points to.CyclicList.cyclicIterator(int)public boolean hasNext()
next()
would return an element rather than throwing an exception.public E next() throws NoSuchElementException
previous
to go back and forth.
(Note that alternating calls
to next and previous
will return the same element repeatedly.)next in interface CyclicIterator<E>next in interface Iterator<E>NoSuchElementException - iteration has no more elements.public boolean hasPrev()
previous()
does not throw an exception.hasPrev in interface CyclicIterator<E>previous()
does not throw an exception.public E previous() throws NoSuchElementException
next to go back and forth.
(Note that alternating calls
to next and previous
will return the same element repeatedly.)previous in interface CyclicIterator<E>NoSuchElementException - if the iteration has no previous element.public int getNextIndexOf(E obj)
next
which equals the given one, if possible;
otherwise returns -1.getNextIndexOf in interface CyclicIterator<E>obj - an object.ind in {0,...,this.cal.size()-1}
satisfying
obj.equals(this.cal.get(ind))
if possible;
-1 if there is no such index.
public void add(E obj)
next, if any,
and after the next element
that would be returned by previous, if any.
(If the cyclic list is empty,
the new element becomes the sole element on the cyclic list.)
The new element is inserted before the implicit cursor:
a subsequent call to next would be unaffected,
and a subsequent call to previous
would return the new element.
(This call increases by one the value
that would be returned by a call
to nextIndex or to previousIndex.)
add in interface CyclicIterator<E>obj - An object to be inserted in the list this iterator points to.CyclicIterator.addAll(java.util.List<? extends E>)public void addAll(List<? extends E> addList)
next, if any,
and after the next element
that would be returned by previous, if any.
(If the cyclic list is empty,
the new cyclic list comprises the given list.)
The given list is inserted before the implicit cursor:
a subsequent call to next would be unaffected,
and a subsequent call to previous
would return the given list in reversed order.
(This call increases by list.size()
the value that would be returned by a call
to nextIndex or previousIndex.)
If list.size()
contains a single element e,
addAll(list) is equivalent with add(e).
addAll in interface CyclicIterator<E>addList - the list to be inserted.CyclicIterator.add(E)public void set(E obj)
next or previous
with the specified element (optional operation).
This call can be made only
if neither ListIterator.remove nor add
have been called after the last call to
next or previous.set in interface CyclicIterator<E>obj - the element with which to replace the last element
returned by next or previous.IllegalStateException - if neither next nor previous
have been called,
or remove or add have been called
after the last call
to next or previous.public void remove()
CyclicList
the last element returned by the iterator.
This method can be called only once
per call to next or to previous.
The behavior of an iterator is unspecified
if the underlying collection is modified
while the iteration is in progress in any way other
than by calling this method.remove in interface CyclicIterator<E>remove in interface Iterator<E>IllegalStateException - if the next method has not yet been called,
or the remove method has already been called
after the last call to the next method.public boolean equals(Object other)
other
is also an instance of CyclicIterator
and, if so, whether the underlying list and the indices coincide.equals in interface CyclicIterator<E>equals in class Objectother - another Object; possibly null.false
if other is not an instance
of CyclicIterator.
Otherwise returns true
if all of the following methods return equal values:
getIndex(), getFirstIndex()
and getCyclicList().public boolean retEquals(CyclicIterator<?> other)
next() is invoked sequentially.retEquals in interface CyclicIterator<E>other - another CyclicIterator.next() is invoked sequentially
as long as possible.
This imposes that the lengths of the sequences coincide.
The elements in the sequence may well be null.public double dist(CyclicIterator<E> other)
dist in interface CyclicIterator<E>public String toString()
Copyright © 2012–2018 Simuline Organization (l2r). All rights reserved.