Package com.globalmentor.collections
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:
java.lang.Iterable<D>
,java.util.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
AbstractConverterCollection.ConverterIterator
A custom proxied iterator that converts returned elements on the fly.
-
Field Summary
-
Fields inherited from class com.globalmentor.collections.CollectionDecorator
collection
-
-
Constructor Summary
Constructors Constructor Description AbstractConverterCollection(java.util.Collection<S> collection)
Collection constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract D
convert(S source)
Converts an object in the collection to another object.java.util.Iterator<D>
iterator()
-
Methods inherited from class com.globalmentor.collections.CollectionDecorator
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, parallelStream, remove, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray
-
-
-
-
Constructor Detail
-
AbstractConverterCollection
public AbstractConverterCollection(java.util.Collection<S> collection)
Collection constructor.- Parameters:
collection
- The collection the elements of which this collection should convert.
-
-
Method Detail
-
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 java.util.Iterator<D> iterator()
- Specified by:
iterator
in interfacejava.util.Collection<S>
- Specified by:
iterator
in interfacejava.lang.Iterable<S>
- Overrides:
iterator
in classCollectionDecorator<D>
- Returns:
- A custom proxied iterator that will convert returned elements on the fly.
-
-