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
**  ---------|------------|-----------------------------------------------
**  24Aug98     subtle       start of recorded history
**
*/

package key;

import key.*;
import key.util.Trie;
import java.io.IOException;

import java.util.Enumeration;
import java.util.StringTokenizer;

public class QuickMove extends Command
{
	public QuickMove()
	{
		setKey( "qmv" );
		usage = "<object> <destination container>";
	}
	
	public void run( Player p, StringTokenizer args, String fullLine, CategoryCommand caller, InteractiveConnection ic, Flags flags ) throws IOException
	{
		String type;

		if( !args.hasMoreTokens() )
			usage( ic );
		else
		{
			String id=args.nextToken();
			if( !args.hasMoreTokens() )
				usage( ic );
			else
			{
				String to=args.nextToken();

				Object o = new Search( id, p.getContext(), false, false ).result;
				if( o != null )
				{
					if( o instanceof Reference )
					{
						Object r = new Search( to, p.getContext() ).result;
						if( r == null )
							ic.sendError( "Could not find destination '" + to + "'" );
						else if( r instanceof Container )
						{
							Container t = (Container)r;
							
							try
							{
								
								if( t.isReference() )
								{
									t.contained.link( (Reference) o );
									ic.sendFeedback( "A reference (" + o.toString() + ") has been placed in " + t.getId() );
								}
								else
									ic.sendFeedback( "Operation not valid for non-reference containers" );
							}
							catch( BadKeyException e )
							{
								throw new UnexpectedResult( e.toString() + " on removing a matched atom" );
							}
							catch( NonUniqueKeyException e )
							{
								ic.sendError( "There already exists an atom with this name in the destination container" );
								return;
							}
						}
						else
							ic.sendError( "'" + to + "' is not a Container, it is a " + Type.typeOf( r ).getName() );
					}
					else if( o instanceof Trie )
						ic.sendError( "Multiple matches: " + ((Trie)o).contents() );
					else if( o instanceof Atom )
						ic.sendError( "Matched atom, not reference." );
					else
						ic.sendError( "'" + id + "' is not an atom, it is " + Type.typeOf( o ).getName() );
				}
				else
					ic.sendError( "Could not find '" + id + "'" );
			}
		}
	}
}