Class AbstractConverterList<S,D>

Type Parameters:
S - The type of element contained in the source list.
D - The type of element contained in the destination list.
All Implemented Interfaces:
Iterable<D>, Collection<D>, List<D>

public abstract class AbstractConverterList<S,D> extends ListDecorator<D>
A list that provides access to another list, automatically converting elements to objects possibly of a different type. The conversion is done on the fly as elements are requested, and not before.
Author:
Garret Wilson
  • Constructor Details

    • AbstractConverterList

      public AbstractConverterList(List<S> list)
      List constructor that converts objects from scratch on each request.
      Parameters:
      list - The list the elements of which this list should convert.
    • AbstractConverterList

      public AbstractConverterList(List<S> list, boolean reuse)
      List and reuse constructor.
      Parameters:
      list - The list the elements of which this list should convert.
      reuse - true if the converter should remember and reuse converted objects, or false if the conversion should take place from scratch upon each request.
  • Method Details

    • convert

      protected abstract D convert(S source)
      Converts an object in the list to another object.
      Parameters:
      source - The object to convert.
      Returns:
      The converted object.
    • get

      public D get(int index)
      Converts and returns the element at the specified position in this list.
      Specified by:
      get in interface List<S>
      Overrides:
      get in class ListDecorator<D>
      Parameters:
      index - The index of element to convert and return.
      Returns:
      The converted element at the specified position in this list.
      Throws:
      IndexOutOfBoundsException - Thrown if the index is out of range (index < 0 || index > size()).
    • iterator

      public Iterator<D> iterator()
      Specified by:
      iterator in interface Collection<S>
      Specified by:
      iterator in interface Iterable<S>
      Specified by:
      iterator in interface List<S>
      Overrides:
      iterator in class CollectionDecorator<D>
      Returns:
      A custom proxied iterator that will convert returned elements on the fly.
    • listIterator

      public ListIterator<D> listIterator()
      Specified by:
      listIterator in interface List<S>
      Overrides:
      listIterator in class ListDecorator<D>
      Returns:
      A custom proxied list iterator that will convert returned elements on the fly.
    • listIterator

      public ListIterator<D> listIterator(int index)
      Returns a custom proxied list iterator that will convert returned elements on the fly.
      Specified by:
      listIterator in interface List<S>
      Overrides:
      listIterator in class ListDecorator<D>
      Parameters:
      index - The index of first element to be returned from the list iterator (by a call to the next method).
      Returns:
      A custom proxied list iterator that will convert returned elements.
      Throws:
      IndexOutOfBoundsException - Thrown if the index is out of range (index < 0 || index > size()).