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

// -*-Mode: JDE-*- 
// $Id: MergeConsecutiveEventsRule.java,v 1.4 2005/02/17 21:40:59 moltmans Exp $
// MergeConsecutiveEventsRule.java -- 
// Author: Michael Oltmans <moltmans@ai.mit.edu> 
// Created: <Mon Jun 05 22:33:45 2000> 
// Time-stamp: <2005-02-16 14:03:39 moltmans> 
package rec.annotate.rules;

import rec.tms.*;
import rec.sys.*;
import java.util.*;
import rec.annotate.facts.*;

public class MergeConsecutiveEventsRule extends AnnotateRule 
{
  
  public LinkedList getTriggers() 
  {
    LinkedList triggers = new LinkedList();
    triggers.add( Type.EVENT );
    triggers.add( Type.EVENT );
    return triggers;
  }

  /**
   * @see Event.sameEvent for details of when 2 events are the
   *      same.
   **/
  public boolean match( LinkedList params ) 
  {
    if( params.size() == 1 )
      return true;

    Event e1 = (Event)params.get(0);
    Event e2 = (Event)params.get(1);

    return ( (e1 != e2) &&
	     e1.sameEvent( e2 ) );
  }

  public void run( Surface s, Notebook book, LinkedList params )
  {
    Event e1 = (Event)params.get(0);
    Event e2 = (Event)params.get(1);

    SameEvent fact = new SameEvent( e1, e2 );
    book.myassert( fact, "MergeConsecutiveEventsRule", params );
  }

  public String toString() 
  {
    return "<Rule: MergeConsecutiveEventsRule>";
  }
  
}
