/*---------------------------------------------------------------------------
File:         			RuleSorter.java
Package:                        JFLAP Version 3.1
Author:				Robyn Geer & Alex Karweit V1.0 06/03/97
Modified:			Ted Hung v3.1 7/20/99
                                
Description of Contents:	Contains class RuleSorter.
				
--------------------------------------------------------------------------*/

/* 
 * Susan H. Rodger, Magda Procopiuc, Octavian Procopiuc, Eric Gramond, Ted Hung
 * Computer Science Department
 * Duke University
 * August 1999
 * Supported by National Science Foundation DUE-9596002, DUE-9555084,
 *  and DUE-9752583
 *
 * Copyright (c) 1999
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms are permitted
 * provided that the above copyright notice and this paragraph are
 * duplicated in all such forms and that any documentation,
 * advertising materials, and other materials related to such
 * distribution and use acknowledge that the software was developed
 * by the author.  The name of the author may not be used to
 * endorse or promote products derived from this software without
 * specific prior written permission.
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

package flap;

/**
  * StringSorter - a binary predicate that is used by the Sorting class
  */

public class RuleSorter implements BinaryPredicate
{

  public RuleSorter()
    {
    }

  /**
    * used when comparing two strings
    * @return true if string a is < b, false if a > b
    */
  public boolean execute(Object a, Object b)
    {
      Rule aRule = (Rule) a;
      Rule bRule = (Rule) b;
      
      if(aRule.getLeftHand().getContents().equals(bRule.getLeftHand().getContents()))
	 return (aRule.toString().compareTo(bRule.toString()) < 0);
      return (aRule.getLeftHand().getContents().compareTo(bRule.getLeftHand().getContents()) < 0);
    }
}

