Package org.chocosolver.util.iterators
Interface ValueIterator
-
- All Known Implementing Classes:
DisposableValueBoundIterator,DisposableValueIterator
public interface ValueIteratorAn interface to declare values iterator. A value iterator can be iterated in 2 ways: bottom-up (from lower bound to upper bound)
and top-down (from upper bound to lower bound).
To iterate in bottom-up way, first call bottomUpInit(), then hasNext() and next().
To iterate in bottom-up way, first call topDownInit(), then hasPrevious() and previous().
Once a way is selected, using the wrong methods can lead to unexpected behaviour.ValueIterator vit = ...; vit.bottomUpInit(); while(vit.hasNext()){ int v = vit.next(); // operate on value v here }ORValueIterator vit = ...; vit.topDownInit(); while(vit.hasPrevious()){ int v = vit.previous(); // operate on value v here }- Since:
- 05/10/11
- Author:
- Charles Prud'homme
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidbottomUpInit()booleanhasNext()Returns true if the iteration has more values.booleanhasPrevious()Returns true if the iteration has more ranges.intnext()Compute and return the next value.intprevious()Compute and return the previous value.voidtopDownInit()Prepare iteration from highest value to smallest value (usinghasPrevious()/previous())
-
-
-
Method Detail
-
bottomUpInit
void bottomUpInit()
-
topDownInit
void topDownInit()
Prepare iteration from highest value to smallest value (usinghasPrevious()/previous())ValueIterator vit = ...; vit.topDownInit(); while(vit.hasPrevious()){ int v = vit.previous(); // operate on value v here }
-
hasNext
boolean hasNext()
Returns true if the iteration has more values. (In other words, returns true if next would return valid value.)ValueIterator vit = ...; vit.bottomUpInit(); while(vit.hasNext()){ int v = vit.next(); // operate on value v here }OR- Returns:
- true if the getIterator has more values.
-
hasPrevious
boolean hasPrevious()
Returns true if the iteration has more ranges. (In other words, returns true if previous would return a valid value.)ValueIterator vit = ...; vit.topDownInit(); while(vit.hasPrevious()){ int v = vit.previous(); // operate on value v here }- Returns:
- true if the getIterator has more values.
-
next
int next()
Compute and return the next value.ValueIterator vit = ...; vit.bottomUpInit(); while(vit.hasNext()){ int v = vit.next(); // operate on value v here }OR- Returns:
- the next element in the iteration.
-
previous
int previous()
Compute and return the previous value.ValueIterator vit = ...; vit.topDownInit(); while(vit.hasPrevious()){ int v = vit.previous(); // operate on value v here }- Returns:
- the previous element in the iteration.
-
-