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

// $Id: PoolBuilder.java,v 1.4 2003/03/06 00:40:39 moltmans Exp $
// Time-stamp: <2000-03-11 18:59:37 moltmans>
package rec.sys;



import java.io.*;
import java.util.*;
import rec.util.*;

public abstract class PoolBuilder implements Serializable
{
  public PoolBuilder()
  {
    m_Id = new Id();
  }

  //////////////////////////////////////////////////////////////////////////////

  /**
   * Called by Surface on each relevant Recognizer.
   *
   * @param w   The last thing added to the Surface, the root Widget
   *     which caused recognition to begin again.
   *
   * 
   */
  public WidgetPool build( Surface s, WidgetPool wp, Widget spark )
  {
    WidgetPool nwp = new WidgetPool();
    Collection c = findRelevantWidgets( s, wp, spark );
    
    if ( c != null ) {
      nwp.add( c );
    }

    return nwp;
  }

  protected abstract Collection findRelevantWidgets( Surface s,
						     WidgetPool wp, 
						     Widget spark );
  
  /**
   * @return the name of the Recognizer
   */
  public final String toString()
  {
    return( getClass().getName() );
  }

  ////////////////////////////////////////////////////////////////////////////

  public final Id getId()
  {
    return( m_Id );
  }

  public final boolean equals( PoolBuilder r )
  {
    return( m_Id.equals( r.m_Id ) );
  }

  ////////////////////////////////////////////////////////////////////////////

  private Id m_Id;
}

////////////////////////////////////////////////////////////////////////////////
