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;

/**
  *  Despite its ultra-trendy name, this is just a
  *  reference container which holds other groups
  *  that a specific group can 'imply'.
  *
  *  In the future, this is probably better done
  *  with a set of custom commands rather than a
  *  container - less resources.
 */
public class Implications extends Container
{
	public Implications()
	{
		super( true );
		setConstraint( Type.RANK );
	}

	protected void addInternal( Reference addedr ) throws BadKeyException,NonUniqueKeyException
	{
		Atom added = (Atom) addedr.get();
		
			//  it's important to ensure that the addition of
			//  this implication doesn't cause a circular
			//  reference...
		if( !(added instanceof Rank) )
			throw new TypeMismatchException( added.getName() + " isn't a rank, the required type for implications" );
		
		Atom p = getParent();
		
		if( p == added )
			throw new CircularException( "making an implication to ourselves is circular" );
		
		if( !(p instanceof Rank) )
			throw new UnexpectedResult( "implications doesn't seem to be linked to a rank" );
		
		Rank r = (Rank) p;
		
		if( ((Rank)added).doesImply( r ) )
			throw new CircularException( "making " + getName() + " imply " + r.getName() + " would cause a circular implication" );
		
		super.addInternal( addedr );
	}
}