mirror of https://github.com/apache/lucene.git
Although HitsIterator doesn't implement Iterator, it follows the Iterator idiom so this is just a simple adapter
(really more of a wrapper) which does implement Iterator. Useful when you want to pass the HitsIterator object into Velocity as a collection and you want to be able to do something like #foreach($hit in $hitIterator) ##display stuff #end git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150809 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4474e5fd64
commit
0a7e5168e5
|
@ -0,0 +1,42 @@
|
||||||
|
package org.apache.lucene.beans;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Acts as an adapter for HitsIterator to comply with the Collections
|
||||||
|
* API.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:kelvint@apache.org">Kelvin Tan</a>
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public final class IteratorAdapter implements Iterator
|
||||||
|
{
|
||||||
|
private HitsIterator hitsIterator;
|
||||||
|
|
||||||
|
public IteratorAdapter(HitsIterator it)
|
||||||
|
{
|
||||||
|
this.hitsIterator = it;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasNext()
|
||||||
|
{
|
||||||
|
return hitsIterator.hasNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object next()
|
||||||
|
{
|
||||||
|
return hitsIterator.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove()
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException(
|
||||||
|
"HitsIterator does not " +
|
||||||
|
"support modification of the hits!");
|
||||||
|
}
|
||||||
|
|
||||||
|
public HitsIterator getHitsIterator()
|
||||||
|
{
|
||||||
|
return hitsIterator;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue