Package eu.simuline.util
Interface CyclicIterator<E>
-
- Type Parameters:
E- the class of the elements to iterate over.
- All Superinterfaces:
java.util.Iterator<E>
- All Known Implementing Classes:
CollectionsExt.NonModifyingCyclicIterator,CyclicArrayList.CyclicArrayIterator
public interface CyclicIterator<E> extends java.util.Iterator<E>An iterator over aCyclicList.CyclicIteratorcorresponds withCyclicLists asIterators orListIterators do withLists.- Version:
- 1.0
- Author:
- Ernst Reissner
- See Also:
CyclicList,ListIterator
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidadd(E obj)Inserts the specified element into the underlying cyclic list (optional operation).voidaddAll(java.util.List<? extends E> list)Inserts the specified list into the underlying cyclic list (optional operation).doubledist(CyclicIterator<E> other)booleanequals(java.lang.Object other)Returnsfalseifotheris not an instance ofCyclicIterator.CyclicList<E>getCyclicList()Returns the cyclic list to which this iterator points.intgetFirstIndex()Returns the cursor of this iterator immediately after it has been created (if not modified since then which is currently not possible.).intgetIndex()Returns the current cursor of this iterator.intgetNextIndexOf(E obj)Returns the (non-negative) index of the next object returned bynextwhich equals the given one, if possible; otherwise returns-1.booleanhasNext()Returnstrueif the iteration has more elements.booleanhasPrev()Returnstrueif this iterator has more elements when traversing the cyclic list in the reverse direction.Enext()Returns the next element in the interation.Eprevious()Returns the previous element in the cyclic list.voidrefresh()Reinitialize this iterator without changing the cursor but such that all elements of the corresponding cyclic list may be accessed successively throughnext().voidremove()Removes from the underlyingCyclicListthe last element returned bynextorprevious(optional operation).booleanretEquals(CyclicIterator<?> other)voidset(E obj)Replaces the last element returned bynextorpreviouswith the specified element (optional operation).voidsetIndex(int index)Sets the given index as cursor of this iterator.
-
-
-
Method Detail
-
getFirstIndex
int getFirstIndex()
Returns the cursor of this iterator immediately after it has been created (if not modified since then which is currently not possible.).- Returns:
- the cursor of this iterator immediately after it has been created (if not modified since then).
- See Also:
CyclicList.cyclicIterator(int)
-
getIndex
int getIndex()
Returns the current cursor of this iterator.- Returns:
- the current cursor of this iterator.
-
getCyclicList
CyclicList<E> getCyclicList()
Returns the cyclic list to which this iterator points. Contract:cyclicList.cyclicIterator(int).getCyclicList() == cyclicListagain.- Returns:
- the cyclic list to which this iterator points.
This may be empty but it may not be
null. - See Also:
CyclicList.cyclicIterator(int)
-
hasNext
boolean hasNext()
Returnstrueif the iteration has more elements. (In other words, returnstrueifnextwould return an element rather than throwing an exception.)- Specified by:
hasNextin interfacejava.util.Iterator<E>- Returns:
trueif the iterator has more elements.
-
next
E next()
Returns the next element in the interation. This method may be called repeatedly to iterate through the list, or intermixed with calls topreviousto go back and forth. (Note that alternating calls tonextandpreviouswill return the same element repeatedly.)- Specified by:
nextin interfacejava.util.Iterator<E>- Returns:
- the next element in the interation.
- Throws:
java.util.NoSuchElementException- iteration has no more elements.
-
hasPrev
boolean hasPrev()
Returnstrueif this iterator has more elements when traversing the cyclic list in the reverse direction. (In other words, returnstrueifpreviouswould return an element rather than throwing an exception.)- Returns:
trueif the list iterator has more elements when traversing the list in the reverse direction.
-
previous
E previous()
Returns the previous element in the cyclic list. This method may be called repeatedly to iterate through the list backwards, or intermixed with calls tonextto go back and forth. (Note that alternating calls tonextandpreviouswill return the same element repeatedly.)- Returns:
- the previous element in the list.
- Throws:
java.util.NoSuchElementException- if the iteration has no previous element.
-
getNextIndexOf
int getNextIndexOf(E obj)
Returns the (non-negative) index of the next object returned bynextwhich equals the given one, if possible; otherwise returns-1.- Parameters:
obj- an object.- Returns:
-
the index minimal index
ind in {0,...,this.list.size()-1}satisfyingobj.equals(this.list.get(ind))if possible; -
-1if there is no such index.
-
the index minimal index
-
setIndex
void setIndex(int index)
Sets the given index as cursor of this iterator. Consider the case first that the underlying listgetCyclicList()is not empty. Thenit.setIndex(index); return it.getIndex();returnsindexagain up toit.getCyclicList().size(). Forit.getCyclicList().isEmpty(), this method does not modify this iterator.- Parameters:
index- an arbitraryintvalue, which may also be negative.
-
add
void add(E obj)
Inserts the specified element into the underlying cyclic list (optional operation). The element is inserted immediately before the next element that would be returned bynext, if any, and after the next element that would be returned byprevious, 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
nextwould be unaffected, and a subsequent call topreviouswould return the new element. (This call increases by one the value that would be returned by a call tonextIndexorpreviousIndex.)- Parameters:
obj- the element to be inserted.- Throws:
java.lang.UnsupportedOperationException- if theaddmethod is not supported by this iterator.java.lang.ClassCastException- if the class of the specified element prevents it from being added to the underlying cyclic list.java.lang.IllegalArgumentException- if some aspect of this element prevents it from being added to the underlying cyclic list.- See Also:
addAll(java.util.List<? extends E>)
-
addAll
void addAll(java.util.List<? extends E> list)
Inserts the specified list into the underlying cyclic list (optional operation). The list is inserted immediately before the next element that would be returned bynext, if any, and after the next element that would be returned byprevious, 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
nextwould be unaffected, and a subsequent call topreviouswould return the given list in reversed order. (This call increases bylist.size()the value that would be returned by a call tonextIndexorpreviousIndex.)If
list.size()contains a single elemente,addAll(list)is equivalent withadd(e).- Parameters:
list- the list to be inserted.- Throws:
java.lang.UnsupportedOperationException- if theaddmethod is not supported by this iterator.java.lang.ClassCastException- if the class of the an element in the specified list prevents it from being added to the underlying list.java.lang.IllegalArgumentException- if some aspect of the an element in the specified list prevents it from being added to the underlying list.- See Also:
add(E)
-
set
void set(E obj)
Replaces the last element returned bynextorpreviouswith the specified element (optional operation). This call can be made only if neitherListIterator.removenoraddhave been called after the last call tonextorprevious.- Parameters:
obj- the element with which to replace the last element returned by next or previous.- Throws:
java.lang.UnsupportedOperationException- if thesetoperation is not supported by this iterator.java.lang.ClassCastException- if the class of the specified element prevents it from being added to this cyclic list.java.lang.IllegalArgumentException- if some aspect of the specified element prevents it from being added to this list.java.lang.IllegalStateException- if neithernextnorprevioushave been called, orremoveoraddhave been called after the last call tonextorprevious.
-
remove
void remove()
Removes from the underlyingCyclicListthe last element returned bynextorprevious(optional operation). This method can be called only once per call tonextorprevious. It can be made only ifaddhas not been called after the last call tonextorprevious.- Specified by:
removein interfacejava.util.Iterator<E>- Throws:
java.lang.UnsupportedOperationException- if theremoveoperation is not supported by this CyclicIterator.java.lang.IllegalStateException- if neithernextnorprevioushave been called, orremoveoraddhave been called after the last call tonextorprevious.
-
refresh
void refresh()
Reinitialize this iterator without changing the cursor but such that all elements of the corresponding cyclic list may be accessed successively throughnext(). On the other hand,previous()throws an exception.
-
retEquals
boolean retEquals(CyclicIterator<?> other)
-
equals
boolean equals(java.lang.Object other)
Returnsfalseifotheris not an instance ofCyclicIterator. The implementation of this interface should not play a role.- Overrides:
equalsin classjava.lang.Object- Parameters:
other- anotherObject.- Returns:
falseifotheris not an instance ofCyclicIterator. The implementation of this interface should not play a role.
-
dist
double dist(CyclicIterator<E> other)
-
-