I want to use Guava to implement a "peekable" ListIterator
that lets me peek at the previous and next list elements without moving the cursor. This is akin to Guava's PeekingIterator
, only bidirectional because Guava's PeekingIterator
only has a next()
method, not a previous()
.
Does this need to be implemented by writing a new PeekingListIterator
class or is there an Guava-intended way to combine the two concepts?
Where's the value in introducing a new "peeking" concept to an iterator that's already easily scrollable in both directions?
If you really want it, you could just implement two trivial static helpers:
public static <T> T peekNext(ListIterator<T> iterator) {
T next = iterator.next();
iterator.previous();
return next;
}
public static <T> T peekPrevious(ListIterator<T> iterator) {
T previous = iterator.previous();
iterator.next();
return previous;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With