RefEntryBackEnd Class

package org.mcraig.cs445.refentry;
import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;

/** 
 * Backend keeping track of RefEntry documents for the servlet. 
 * @author <a href="mailto:mark@mcraig.org">Mark Craig</a>
 */
class RefEntryBackEnd implements Serializable {
    /** 
     * Default constructor.
     * @param cw Common words to ignore when indexing.
     */
    RefEntryBackEnd(HashSet cw) {
        Index       = new RefEntryIndex();
        Entries     = new HashMap();
        CommonWords = cw;
    }
    /**
     * Add a unique, formatted RefEntry document to those tracked.
     * @param page RefEntry document to add.
     */
    boolean add(RefEntry page) {
        // Add the page to the set of all known documents.
        if (Entries.containsKey(page.getID())) return false;
        Entries.put(page.getID(), page);

        // Add the page to the index.
        HashSet  keys  = page.getKeys(CommonWords);
        Iterator iter  = keys.iterator();
        while (iter.hasNext()) {
            Index.add((String)iter.next(), page);
        }
        return true;
    }
    /**
     * Return a set of RefEntry documents.
     * @param keys Strings to match in RefEntry documents.
     */
    HashSet getValues(HashSet keys) {
        HashSet values = new HashSet();
        Iterator iter  = keys.iterator();
        while (iter.hasNext()) {
            values.addAll(Index.match((String)iter.next()));
        }
        return values;
    }
    /**
     * Return a single RefEntry as a set.
     * @param id RefEntry identifier.
     */
    HashSet getEntry(String id) {
        HashSet set = new HashSet();
        if (Entries.containsKey(id) && Entries.get(id) != null)
            set.add(Entries.get(id));
        return set;
    }
    /** Set common words to ignore when indexing. */
    private HashSet CommonWords;
    /** Index holding tokens corresponding to RefEntry documents. */
    private RefEntryIndex Index;
    /** Set of all known RefEntry documents. */
    private HashMap Entries;
}