import java.util.*;
import java.io.*;

/** Manage a set of arrays,
 *  so that a key can correspond to an array of Objects,
 *  instead of a single Object.
 *
 *  Note that methods returning Object [] arrays cannot be cast
 *  to an array of some more specific class that was used
 *  for setting the values.
 *
 *  Instead, cast the individual elements of the Object [] array
 *  to the actual value class.
 *
 *  Inherited Hashtable methods we can use as-is:

 *  constructors (); or (int size); or (int size, float factor);

 *  void clear ();
 *  boolean contains (Value);
 *  boolean containsKey (Key);
 *  int size () -- number of Keys
 *  Enumeration keys ()
 * <IMG SRC="/cgi-bin/counter">
 *
 * @author Morris Hirsch
 */

public class HashLink extends Hashtable {

/** Returns former definition or null */

    public Object [] put (String key, Object value) {

       if ((null == key)
	 || (0 == key.trim ().length ()))
	     return null;

       Object []current = get (key);
       Object []putvalues;

/* Array of one at first key appearance */

       if (null == current) {
	   putvalues = new Object [1];
	   putvalues[0] = value;
       }

/* At later key appearance,
 * if the Object to be added is already present,
 * just return former definition.
 * Otherwise extend the array and append this value. */

       else {
	    int nrows = current.length;

	    int ii;
	    for (ii = 0; ii < nrows; ii++)
		if (value == current[ii])
		    return current;

	    putvalues = new Object[nrows+1];
	    System.arraycopy
		(current, 0,
		 putvalues, 0, nrows);
	    putvalues[nrows] = value;
       }

       return (Object []) super.put (key, putvalues);
    }

/** Returns current definition or null */

    public Object []get (String key) {

       if ((null == key)
	 || (0 == key.trim ().length ()))
	     return null;

        return (Object []) super.get (key);
    }

/** Returns former definition or null */

    public Object []remove (String key) {

       if ((null == key)
	 || (0 == key.trim ().length ()))
	     return null;

        return (Object []) super.remove (key);
    }

/** Returns current Key names as String [],
 *  an alternative to inherited Enumeration keys () method,
 *  possible because our Keys are Strings. */

    public String []getKeyStrings () {
	int ii = 0;
	String []mNames = new String [size ()];
	Enumeration mKeys = keys ();
	while (mKeys.hasMoreElements())
	      mNames[ii++] = (String)mKeys.nextElement();
	return mNames;
    }


}
/* <IMG SRC="/cgi-bin/counter">*/
