You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by ke...@apache.org on 2002/08/31 03:19:43 UTC

cvs commit: jakarta-lucene-sandbox/contributions/searchbean/src/java/org/apache/lucene/beans IteratorAdapter.java

kelvint     2002/08/30 18:19:43

  Added:       contributions/searchbean/src/java/org/apache/lucene/beans
                        IteratorAdapter.java
  Log:
  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
  
  Revision  Changes    Path
  1.1                  jakarta-lucene-sandbox/contributions/searchbean/src/java/org/apache/lucene/beans/IteratorAdapter.java
  
  Index: IteratorAdapter.java
  ===================================================================
  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: IteratorAdapter.java,v 1.1 2002/08/31 01:19:42 kelvint Exp $
   */
  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;
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>