Class AbstractConverterCollection<S,D>

java.lang.Object
com.globalmentor.collections.CollectionDecorator<D>
com.globalmentor.collections.AbstractConverterCollection<S,D>
Type Parameters:
S - The type of element contained in the source collection.
D - The type of element contained in the destination collection.
All Implemented Interfaces:
Iterable<D>, Collection<D>

public abstract class AbstractConverterCollection<S,D> extends CollectionDecorator<D>
A collection that provides access to another collection, 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

    • AbstractConverterCollection

      public AbstractConverterCollection(Collection<S> collection)
      Collection constructor.
      Parameters:
      collection - The collection the elements of which this collection should convert.
  • Method Details

    • convert

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

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