Class StridingBooleanIterator
java.lang.Object
com.github.tommyettinger.ds.support.util.StridingBooleanIterator
- All Implemented Interfaces:
BooleanIterator,Iterator<Boolean>
Wraps a BooleanIterator so that it starts at an offset, skipping that many items, then returning items that match a given
stride, such as every other item, or every tenth item. If the offset is 0, this will try to return the first item and
then any items matching the stride, so if the stride is 2, it will return the first item, skip one item, return the
item after that, skip, return, skip, return, etc.
This has undefined behavior if any items the BooleanIterator could return are modified during iteration.
You can change the iterator, offset, and stride at once using
You can change the iterator, offset, and stride at once using
set(BooleanIterator, int, int), and can also just
change the iterator with set(BooleanIterator).-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanhasNext()booleanReturns the nextbooleanelement in the iteration.voidremove()NOTE: this does not change the stride or offset, so the same sequence of values will be returned regardless of if some elements are removed with this method.voidset(BooleanIterator iterator) voidset(BooleanIterator iterator, int offset, int stride) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.github.tommyettinger.ds.support.util.BooleanIterator
forEachRemaining, nextMethods inherited from interface java.util.Iterator
forEachRemaining
-
Field Details
-
iterator
-
offset
protected int offset -
stride
protected int stride -
index
protected int index -
end
protected boolean end -
available
protected boolean available -
next
protected boolean next
-
-
Constructor Details
-
StridingBooleanIterator
public StridingBooleanIterator() -
StridingBooleanIterator
-
-
Method Details
-
set
-
set
-
hasNext
public boolean hasNext() -
nextBoolean
public boolean nextBoolean()Description copied from interface:BooleanIteratorReturns the nextbooleanelement in the iteration.- Specified by:
nextBooleanin interfaceBooleanIterator- Returns:
- the next
booleanelement in the iteration
-
remove
public void remove()NOTE: this does not change the stride or offset, so the same sequence of values will be returned regardless of if some elements are removed with this method.
-