From 0a7e5168e5d154caba394b637752dcb45e48b2bb Mon Sep 17 00:00:00 2001 From: Kelvin Tan Date: Sat, 31 Aug 2002 01:19:42 +0000 Subject: [PATCH] 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 --- .../apache/lucene/beans/IteratorAdapter.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 sandbox/contributions/searchbean/src/java/org/apache/lucene/beans/IteratorAdapter.java diff --git a/sandbox/contributions/searchbean/src/java/org/apache/lucene/beans/IteratorAdapter.java b/sandbox/contributions/searchbean/src/java/org/apache/lucene/beans/IteratorAdapter.java new file mode 100644 index 00000000000..49f18c31edc --- /dev/null +++ b/sandbox/contributions/searchbean/src/java/org/apache/lucene/beans/IteratorAdapter.java @@ -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 Kelvin Tan + * @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; + } +}