org.ontoware.rdf2go.util
Class ConvertingIterator<FROM,TO>

java.lang.Object
  extended by org.ontoware.rdf2go.util.ConvertingIterator<FROM,TO>
Type Parameters:
FROM - The class that is the source of conversion
TO - The class that is converted to Note: as this class is not RDF-specific in any way it is a good candidate for AIFBcommons.
All Implemented Interfaces:
java.util.Iterator<TO>

public class ConvertingIterator<FROM,TO>
extends java.lang.Object
implements java.util.Iterator<TO>

An iterator that converts from "FROM" to "TO", by wrapping an existing iterator. This is needed when converting statements or resource-uris from one iterator to another, for the Adapter implementations. You still have to implement the "convert" method, but the handling of the Java generics is done.

Author:
sauermann

Constructor Summary
ConvertingIterator(java.util.Iterator<FROM> wrapped)
          The iterator takes the wrapped class and converts it to other classes on the fly.
ConvertingIterator(java.util.Iterator<FROM> wrapped, Converter<FROM,TO> converter)
          The iterator takes the wrapped class and converts it to other classes on the fly.
 
Method Summary
 TO convert(FROM next)
          convert the passed object to the outgoing object
 boolean hasNext()
           
 TO next()
           
 void remove()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConvertingIterator

public ConvertingIterator(java.util.Iterator<FROM> wrapped)
The iterator takes the wrapped class and converts it to other classes on the fly. You have to override the "convert" method, though.

Parameters:
wrapped - the wrapped iterator

ConvertingIterator

public ConvertingIterator(java.util.Iterator<FROM> wrapped,
                          Converter<FROM,TO> converter)
The iterator takes the wrapped class and converts it to other classes on the fly. Pass a converter that handles the conversion.

Parameters:
wrapped - the wrapped iterator
converter - the converter
Method Detail

hasNext

public boolean hasNext()
Specified by:
hasNext in interface java.util.Iterator<TO>
See Also:
Iterator.hasNext()

next

public TO next()
Specified by:
next in interface java.util.Iterator<TO>
See Also:
Iterator.next()

convert

public TO convert(FROM next)
convert the passed object to the outgoing object

Parameters:
next - the next object to convert
Returns:
the converted object

remove

public void remove()
Specified by:
remove in interface java.util.Iterator<TO>
See Also:
Iterator.remove()


Copyright © 2005-2008 FZI - Forschungszentrum Informatik | Karlsruhe | Germany. All Rights Reserved.