FileDocCategorySizeDatePackage
Hashvector.javaAPI DocExample1624Thu Feb 17 20:00:42 GMT 2000com.togethersoft.modules.genidl

Hashvector.java

/*----------------------------------------------------------------------------
Copyright (c)2000 TogetherSoft LLC. Patents pending. All rights reserved.
----------------------------------------------------------------------------*/

package com.togethersoft.modules.genidl;

import java.util.Hashtable;
import java.util.Vector;
import java.util.Enumeration;
import com.togethersoft.util.enum.EmptyEnumeration;

/** Hashvector. A hashtable that contains several elements per key. */
public class Hashvector {
    public Hashvector() {
        myHashtable = new Hashtable();
    }

    public void put(Object key, Object value) {
        Vector cell;
        if (myHashtable.containsKey(key)) {
            cell = (Vector)myHashtable.get(key);
        }
        else {
            cell = new Vector();
        }
        cell.addElement(value);
        myHashtable.put(key, cell);
    }

    /**
     * Instead of get method of Hashtable we have elements(key) method
     * that returns an enumeration of elements put with given key
     */
    public Enumeration elements(Object key) {
        Vector cell = (Vector)myHashtable.get(key);
        if (cell == null) {
            return EmptyEnumeration.getInstance();
        }
        return cell.elements();
    }

    /** Another possibility to access elements is to get Vector of elements by key */
    public Vector get(Object key) {
        return (Vector)myHashtable.get(key);
    }

    public boolean containsKey(Object key) {
        return myHashtable.containsKey(key);
    }

    private Hashtable myHashtable;
}