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

// -*-Mode: Java-*- 
// $Id: SubEvent.java,v 1.4 2003/03/06 00:40:49 moltmans Exp $
// SubEvent.java -- 
// Author: Michael Oltmans <moltmans@ai.mit.edu> 
// Created: <Mon May 22 18:06:13 2000> 
// Time-stamp: <2000-07-19 17:05:26 moltmans> 
package rec.annotate.facts;

import rec.annotate.rules.*;
import java.util.*;
import rec.tms.*;
import rec.annotate.*;
import rec.annotate.rules.*;

/**
 * Indicate that one event is made of of several sub events.
 **/
public class SubEvent extends Annotation
{
  protected Event m_composite;
  protected LinkedList m_subEvents;

  public SubEvent( Event composite, LinkedList subEvents )
  {
    super( Math.min( composite.getStartTime(),
		     Annotation.getMinTime( subEvents ) ),
	   Math.max( composite.getEndTime(),
		     Annotation.getMaxTime( subEvents ) ) );
    m_composite = composite;
    m_subEvents = new LinkedList( subEvents );
  }


  public String getFactType() 
  {
    return Type.SUB_EVENT;
  }

  public List getSubEvents()
  {
    return m_subEvents;
  }

  public Event getEvent()
  {
    return m_composite;
  }

  public boolean sameFact( Fact fact ) 
  {
    if( fact instanceof SubEvent ) {
      SubEvent f = (SubEvent)fact;
      return ( m_composite.sameFact( f.m_composite ) &&
	       Annotation.sameFacts( m_subEvents, f.m_subEvents ) );
    }
    return false;
  }

  public String toEnglish() 
  {
    return m_composite.toEnglish() + " is composed from  " +
      m_subEvents;
  }

  public String toString() 
  {
    return "<SubEvent: [" + m_composite + "] [" + m_subEvents + "]>";
  }

}
