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

// $Id: TemporalPoolBuilder.java,v 1.5 2003/03/06 00:40:48 moltmans Exp $
// Time-stamp: <2000-03-16 19:56:04 moltmans>
package rec.core;



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

public class TemporalPoolBuilder extends PoolBuilder 
{

  private long m_TimeStep;

  public TemporalPoolBuilder( long timestep )
  {
    super();
    
    m_TimeStep = timestep;
  }

  protected Collection findRelevantWidgets( Surface s, WidgetPool wp, 
					    Widget sw )
  {
    Collection relevant = new HashSet();

    long curr_time = sw.getTime();
    long time_diff;
    
    Iterator it = wp.iterator();
    while( it.hasNext() ) {
      Widget w = (Widget)it.next();
      time_diff = curr_time - w.getTime();
      if ( (curr_time - w.getTime()) < m_TimeStep ) {
  	Console.writeln( w + " is relevant. Time diff is " + time_diff );
	relevant.add( w );
	curr_time = w.getTime();
      }
      else {
	Console.writeln( w + " is not relevant.  Time diff is " + time_diff );
	break;
      }
    }

    return relevant;
  }

}
