Package com.globalmentor.collections
Class AbstractConverterList<S,D>
java.lang.Object
com.globalmentor.collections.CollectionDecorator<E>
com.globalmentor.collections.ListDecorator<D>
com.globalmentor.collections.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>
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
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
A custom proxied iterator that converts returned elements on the fly.protected class
A custom proxied list iterator that converts returned elements on the fly. -
Field Summary
Fields inherited from class com.globalmentor.collections.ListDecorator
list
Fields inherited from class com.globalmentor.collections.CollectionDecorator
collection
-
Constructor Summary
ConstructorDescriptionAbstractConverterList
(List<S> list) List constructor that converts objects from scratch on each request.AbstractConverterList
(List<S> list, boolean reuse) List and reuse constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract D
Converts an object in the list to another object.get
(int index) Converts and returns the element at the specified position in this list.iterator()
listIterator
(int index) Returns a custom proxied list iterator that will convert returned elements on the fly.Methods inherited from class com.globalmentor.collections.ListDecorator
add, addAll, indexOf, lastIndexOf, remove, replaceAll, set, sort, subList
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
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream
-
Constructor Details
-
AbstractConverterList
List constructor that converts objects from scratch on each request.- Parameters:
list
- The list the elements of which this list should convert.
-
AbstractConverterList
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, orfalse
if the conversion should take place from scratch upon each request.
-
-
Method Details
-
convert
Converts an object in the list to another object.- Parameters:
source
- The object to convert.- Returns:
- The converted object.
-
get
Converts and returns the element at the specified position in this list.- Specified by:
get
in interfaceList<S>
- Overrides:
get
in classListDecorator<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
-
listIterator
- Specified by:
listIterator
in interfaceList<S>
- Overrides:
listIterator
in classListDecorator<D>
- Returns:
- A custom proxied list iterator that will convert returned elements on the fly.
-
listIterator
Returns a custom proxied list iterator that will convert returned elements on the fly.- Specified by:
listIterator
in interfaceList<S>
- Overrides:
listIterator
in classListDecorator<D>
- Parameters:
index
- The index of first element to be returned from the list iterator (by a call to thenext
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()).
-