ch.panter.li.bi.util
Class ReinterpretingIterator<SourceType,TargetType>

java.lang.Object
  extended by ch.panter.li.bi.util.ReinterpretingIterator<SourceType,TargetType>
All Implemented Interfaces:
Iterator<TargetType>

public class ReinterpretingIterator<SourceType,TargetType>
extends Object
implements Iterator<TargetType>

A simple iterator that re-interprets the values of another iterator as a different type. This is sometimes necessary for typed collections which should deliver their contents under different aspects which are not recognizable by the compiler as being class-related. E.g. if a class A implements interfaces B and C while the collection is of type C and holds only instances of A. As the two interfaces B and C are not related, the compiler has no idea that it might be allowed to re-interpret the Cs of the collection into Bs. The collection however (or the owner of it) might very well ensure that only As are added to it and thus can return its contents as B or C instances, hence this iterator.
The user of this class is expected to be cautious to only create instances of this class which are able to perform the desired task. ClassCastException will be thrown upon usage with objects which are not convertible from the source- to the target-type (due to the java generics mechanism which works at compile-time and doens't preserve that information in the byte code for examination by this class).


Constructor Summary
ReinterpretingIterator(Iterator<SourceType> contents)
           
 
Method Summary
 boolean hasNext()
           
 TargetType next()
           
 void remove()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReinterpretingIterator

public ReinterpretingIterator(Iterator<SourceType> contents)
Method Detail

hasNext

public boolean hasNext()
Specified by:
hasNext in interface Iterator<TargetType>

next

public TargetType next()
Specified by:
next in interface Iterator<TargetType>

remove

public void remove()
Specified by:
remove in interface Iterator<TargetType>


Copyright 2007-2007 SourceForge. All Rights Reserved.