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

// -*-Mode: Java-*- 
// WidgetTimeComparator.java -- 
// Author: Christine Alvarado <calvarad@ai.mit.edu> 
// Maintainer: Christine Alvarado <calvarad@ai.mit.edu> 
// Version: 
// Created: <Tue Feb 15 17:01:37 2000> 
// Time-stamp: <2000-02-15 19:35:36 calvarad> 
// Keywords: 

package rec.util;

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

/** Orders from greatest to least time **/
public class WidgetTimeComparator implements java.util.Comparator
{
  public WidgetTimeComparator()
  {
  }
  
  public int compare( Object o1, Object o2 )
  {
    Assert.check( (o1 instanceof Widget) && (o2 instanceof Widget) );
    long t1 = ((Widget)o1).getTime();
    long t2 = ((Widget)o2).getTime();
    
    if ( o1.equals( o2 ) ) {
      return 0;
    }
    
    if ( t1 == t2 ) {
      Id id1 = (Id)((Widget)o1).getId();
      Id id2 = (Id)((Widget)o2).getId();
      if ( ( id1.compareTo( id2 ) ) > 0 ) {
	return 1;
      }
      else {
	return -1;
      }
    }
    
    if ( t1 > t2 ) {
      return 1;
    }
    
    return -1;
    
  }
  
}
