key0-96/
key0-96/doc/key/
key0-96/doc/key/credits/
key0-96/doc/key/developers/
key0-96/doc/key/developers/resources/
key0-96/setup/caves/
key0-96/setup/help/
key0-96/setup/ruins/
key0-96/src/
key0-96/src/commands/
key0-96/src/events/
key0-96/src/hack/
key0-96/src/sql/
key0-96/src/swing/
key0-96/src/talker/forest/
key0-96/src/talker/objects/
key0-96/src/terminals/
/*
**               j###t  ########## ####   ####
**              j###t   ########## ####   ####
**             j###T               "###L J###"
**          ######P'    ##########  #########
**          ######k,    ##########   T######T
**          ####~###L   ####
**          #### q###L  ##########   .#####
**          ####  \###L ##########   #####"
**
**  $Id$
**
**  Class History
**
**  Date        Name         Description
**  ---------|------------|-----------------------------------------------
**  19Aug98     subtle       start of recorded history
**
*/

package key.collections;

import key.*;

import java.util.Enumeration;
import java.io.IOException;
import java.io.DataInput;
import java.io.DataOutput;
import java.util.NoSuchElementException;
import java.util.Hashtable;

public final class NetworkCollection extends SiteCollection
{
	private Hashtable theHash;
	
	public NetworkCollection()
	{
		theHash = new Hashtable();
	}
	
	public void link( Symbol a ) throws NonUniqueKeyException,BadKeyException
	{
		super.link( a );
		
		Object o = ((Reference)a).get();

		if( o instanceof Site )
		{
			Site s = (Site) o;
			
			String trail = s.getTrailer();
			
			if( trail != null )
				theHash.put( trail, a );
		}
	}

	public void unRegister( String s )
	{
		theHash.remove( s );
	}

	public void register( String s, Symbol a )
	{
		theHash.put( s, a );
	}
	
	public void unlink( Symbol a ) throws NoSuchElementException,BadKeyException
	{
		super.unlink( a );
		
		Object o = ((Reference)a).get();
		
		if( o instanceof Site )
		{
			Site s = (Site) o;
			
			String trail = s.getTrailer();
			
			if( trail != null )
				theHash.remove( trail );
		}
	}
	
	/**
	  * Returns the atom matched, or, possibly, an instance of
	  * a Trie object that contains all the matching atoms.
	  * <p>
	  * A null is returned if no matches were found at all.  The
	  * match string is searched until the end of the string or
	  * a non-alphabetical character is found.
	  *
	  * @param match the start or whole string to match from
	  * @return An atom object, referring to the sole match, or a Trie
	 */
	public Object get( Object key )
	{
		Object result = null;
		
		try
		{
			result = super.get( key );
		}
		catch( NumberFormatException e )
		{
				//  maybe we're dealing with an alpha
			result = theHash.get( key );
		}
		
		return( result );
	}
}