home *** CD-ROM | disk | FTP | other *** search
/ ActiveX Programming Unleashed CD / AXU.iso / jgl_1_1 / jgl_1_1.exe / src / HashComparator.java < prev    next >
Encoding:
Java Source  |  1996-09-10  |  1.0 KB  |  31 lines

  1. // Copyright(c) 1996 ObjectSpace, Inc.
  2. // Portions Copyright(c) 1995, 1996 Hewlett-Packard Company.
  3.  
  4. package jgl;
  5.  
  6. /**
  7.  * HashComparator is a binary predicate that returns true if the hash code of its
  8.  * first operand is less than the hash code of its second operand. It is used as the
  9.  * default comparator by many algorithms and containers. It is especially useful for
  10.  * sorting numbers, as the hash code of the Number subclasses are equal to their primitive
  11.  * value.
  12.  * <p>
  13.  * @version 1.1
  14.  * @author ObjectSpace, Inc.
  15.  */
  16.  
  17. public final class HashComparator implements BinaryPredicate
  18.   {
  19.   /**
  20.    * Compare the operands based on their hash code.
  21.    * @param first The first object.
  22.    * @param second The second object.
  23.    * @return true if the hash code of the first operand is less than the hash code of 
  24.    * the second operand using the standard Java hashCode() method.
  25.    */
  26.   public boolean execute( Object first, Object second )
  27.     {
  28.     return first.hashCode() < second.hashCode();
  29.     }
  30.   }
  31.