Is it possible to combine Guava ForwardingListIterator with PeekingIterator?

I want to use Guava to implement a "peekable" ListIterator , which allows me to look at the previous and next list items without moving the cursor. This is similar to Guava PeekingIterator , only bidirectional, as Guava PeekingIterator has next() , not previous() .

Is it necessary to implement this by writing a new PeekingListIterator class PeekingListIterator or is there a way that can be used for use in Guava for two concepts?

+4
source share
1 answer

What is the significance of introducing a new named "drop-in" concept into an iterator that already scrolls easily in both directions?

If you really want this, you can simply 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; } 
+14
source

Source: https://habr.com/ru/post/1399650/


All Articles