JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / src / jalview / util / ReverseListIterator.java
1 package jalview.util;
2
3 import java.util.Iterator;
4 import java.util.List;
5 import java.util.ListIterator;
6
7 /**
8  * An iterator that traverses a list backwards.
9  * 
10  * @author gmcarstairs (and checked against
11  *         org.codehaus.groovey.runtime.ReverseListIterator)
12  *
13  * @param <E>
14  */
15 public class ReverseListIterator<E> implements Iterator<E>
16 {
17
18   private ListIterator<E> iterator;
19
20   public ReverseListIterator(List<E> stuff)
21   {
22     this.iterator = stuff.listIterator(stuff.size());
23   }
24   @Override
25   public boolean hasNext()
26   {
27     return iterator.hasPrevious();
28   }
29
30   @Override
31   public E next()
32   {
33     return iterator.previous();
34   }
35
36   @Override
37   public void remove()
38   {
39     iterator.remove();
40   }
41
42 }