// (c) MIT 2003.  All rights reserved.

package rec.fsm;

///////////////////////////////////////////////////////////////////////////////
//
// FILE:	EdgeDupReducer.java
//
// AUTHOR:      Luke Weisman
//              luke@ai.mit.edu
//
// DATE:	June, 1998
//
// COPYRIGHT:	Massachusetts Institute of Technology
//		All rights reserved.
//
//
///////////////////////////////////////////////////////////////////////////////


import java.util.*;
import rec.util.*;
import rec.sys.*;
import rec.core.*;

public class EdgeDupReducer extends Aligner
{

  public EdgeDupReducer()
  {
  }


  public boolean recognize( Surface s, Widget w )
  {
    EdgeDup e = (EdgeDup)w;

    return reduce( s, e );
  }

  public static boolean reduce( Surface s, EdgeDup ed )
  {
	
    // if edge not connected to anything or only edge connecting something
    // then reduce it.
    if ( !ed.full() 
	 || (ed.getNode(true).getEdgesTo( ed.getNode( false ) )).size() == 1 )
      {
	Edge ned = new Edge( ed );
	s.replaceWidget( ed, ned );

	return true;
      }

    return false;
  }


  public Iterator getInputTypes()
  {
    Vector v = new Vector();

    v.addElement( "rec.fsm.EdgeDup" );

    return( v.iterator() );
  }

  public Iterator getOutputTypes()
  {
    return getInputTypes();
  }
  
}


