home | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Lucene example source code file (BufferingTermFreqIteratorWrapper.java)

This example Lucene source code file (BufferingTermFreqIteratorWrapper.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Lucene tags/keywords

arraylist, arraylist, bufferingtermfreqiteratorwrapper, bufferingtermfreqiteratorwrapper, comparable, entry, entry, list, string, string, termfreqiterator, unsupportedoperationexception, util

The Lucene BufferingTermFreqIteratorWrapper.java source code

package org.apache.lucene.search.suggest;

import java.util.ArrayList;
import java.util.List;

import org.apache.lucene.search.spell.TermFreqIterator;

 * This wrapper buffers incoming elements.
public class BufferingTermFreqIteratorWrapper implements TermFreqIterator {

  /** Entry in the buffer. */
  public static final class Entry implements Comparable<Entry> {
    String word;
    float freq;
    public Entry(String word, float freq) {
      this.word = word;
      this.freq = freq;
    public int compareTo(Entry o) {
      return word.compareTo(o.word);

  protected ArrayList<Entry> entries = new ArrayList();
  protected int curPos;
  protected Entry curEntry;
  public BufferingTermFreqIteratorWrapper(TermFreqIterator source) {
    // read all source data into buffer
    while (source.hasNext()) {
      String w = source.next();
      Entry e = new Entry(w, source.freq());
    curPos = 0;

  public float freq() {
    return curEntry.freq;

  public boolean hasNext() {
    return curPos < entries.size();

  public String next() {
    curEntry = entries.get(curPos);
    return curEntry.word;

  public void remove() {
    throw new UnsupportedOperationException("remove is not supported");
  public List<Entry> entries() {
    return entries;

Other Lucene examples (source code examples)

Here is a short list of links related to this Lucene BufferingTermFreqIteratorWrapper.java source code file:

my book on functional programming


new blog posts


Copyright 1998-2019 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.