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:
    java.lang.Iterable<D>, java.util.Collection<D>, java.util.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 Detail

      • AbstractConverterList

        public AbstractConverterList​(java.util.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​(java.util.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 Detail

      • 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 java.util.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:
        java.lang.IndexOutOfBoundsException - Thrown if the index is out of range (index < 0 || index > size()).
      • iterator

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

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

        public java.util.ListIterator<D> listIterator​(int index)
        Returns a custom proxied list iterator that will convert returned elements on the fly.
        Specified by:
        listIterator in interface java.util.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:
        java.lang.IndexOutOfBoundsException - Thrown if the index is out of range (index < 0 || index > size()).