Class ListIndexedIterable<T>

  • All Implemented Interfaces:
    Iterable<T>, IndexedIterable<T>

    public class ListIndexedIterable<T>
    extends Object
    implements IndexedIterable<T>
    Adapts a List to the IndexedIterable interface.
    Version:
    $Revision$ $Date$
    Author:
    Nick Collier
    • Constructor Detail

      • ListIndexedIterable

        public ListIndexedIterable​(List<T> list)
        Creates a ListIndexedIterable that adapts the specified list to the IndexedIterable interface.
        Parameters:
        list -
    • Method Detail

      • get

        public T get​(int index)
        Gets the element at the specified position in this IndexedIterable. Note that this method is should be used for random access to the collection. iterator() is the preferred way to iterate through this IndexedIterable.
        Specified by:
        get in interface IndexedIterable<T>
        Parameters:
        index - the index of the element to return
        Returns:
        the element at the specified position in this IndexedIterable.
        Throws:
        IndexOutOfBoundsException - if the given index is out of range (index < 0 || index >= size()).
      • size

        public int size()
        Gets the number of elements in this IndexedIterable.
        Specified by:
        size in interface IndexedIterable<T>
        Returns:
        the number of elements in this IndexedIterable.
      • iterator

        public Iterator<T> iterator()
        Returns an iterator over a set of elements of type T.
        Specified by:
        iterator in interface Iterable<T>
        Returns:
        an Iterator.