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

// -*-Mode: Java-*- 
// $Id: DBClass.java,v 1.3 2003/03/06 00:40:39 moltmans Exp $
// DBClass.java -- 
// Author: Michael Oltmans <moltmans@ai.mit.edu> 
// Created: <Sun Apr 30 01:41:37 2000> 
// Time-stamp: <2000-05-22 19:40:01 moltmans> 
package rec.tms;

import java.util.*;

/**
 * This class represents classes of data that can be put into the TMS.
 * It also serves as a place to store rules and facts of that type.
 **/
public class DBClass
{
  private String m_name;
  /** Datums that fall into this dbclass **/
  private LinkedList m_facts;
  /** Rules that are triggered by this dbclass **/
  private LinkedList m_rules;

  DBClass( String name ) 
  {
    m_name = name;
    m_facts = new LinkedList();
    m_rules = new LinkedList();
  }

  void addFact( Datum fact ) 
  {
    m_facts.add( fact );
  }

  void addRule( InternalRule rule ) 
  {
    m_rules.add( rule );
  }

  /** @return List of datums that fall into this dbclass **/
  LinkedList getFacts() 
  {
    return m_facts;
  }

  /**
   * @return List of datums that fall into this dbclass and are
   *         currently believed **/
  LinkedList getInFacts() 
  {
    LinkedList list = new LinkedList( m_facts );
    Iterator it = list.iterator();
    while( it.hasNext() ) {
      Datum datum = (Datum)it.next();
      if( datum.getNode().isOut() )
	it.remove();
    }
    return list;
  }

  /** @return List of rules triggered by this dbclass **/
  LinkedList getRules()
  {
    return m_rules;
  }
  

  public String toString() 
  {
    return "<DBClass " + m_name + ">";
  }
  
}
