org.eclipse.xtext.nodemodel.util
Class SingletonBidiIterable<T>

java.lang.Object
  extended by org.eclipse.xtext.nodemodel.util.SingletonBidiIterable<T>
All Implemented Interfaces:
java.lang.Iterable<T>, BidiIterable<T>

public class SingletonBidiIterable<T>
extends java.lang.Object
implements BidiIterable<T>

Author:
Sebastian Zarnekow - Initial contribution and API

Constructor Summary
SingletonBidiIterable(T value)
           
 
Method Summary
static
<T> SingletonBidiIterable<T>
create(T value)
           
 BidiIterator<T> iterator()
          Returns an iterator that can be used forwards and backwards.
 BidiIterable<T> reverse()
          Returns a reverse version of this iterable that can be used forwards and backwards.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SingletonBidiIterable

public SingletonBidiIterable(T value)
Method Detail

create

public static <T> SingletonBidiIterable<T> create(T value)

iterator

public BidiIterator<T> iterator()
Description copied from interface: BidiIterable
Returns an iterator that can be used forwards and backwards.

Specified by:
iterator in interface java.lang.Iterable<T>
Specified by:
iterator in interface BidiIterable<T>
Returns:
an iterator. Never returns null.

reverse

public BidiIterable<T> reverse()
Description copied from interface: BidiIterable

Returns a reverse version of this iterable that can be used forwards and backwards. In other words, an iterator provided by the reverse iterable will delegate its hasNext() and next() invocations to BidiIterator.hasPrevious() and BidiIterator.previous() respectively.

This allows clients to iterate backwards by means of the enhanced for-loop:

 for(T t: iterable.reverse()) {
   // do something with t
 }
 

Specified by:
reverse in interface BidiIterable<T>
Returns:
the reversed iterable. Never returns null.