home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Extras / OSpace / jgl.exe / jgl_2_0 / src / COM / objectspace / jgl / GreaterEqualCollationKey.java < prev    next >
Encoding:
Java Source  |  1997-03-14  |  2.3 KB  |  69 lines

  1. // Copyright(c) 1997 ObjectSpace, Inc.
  2.  
  3. package COM.objectspace.jgl;
  4.  
  5. import java.text.Collator;
  6. import java.text.CollationKey;
  7.  
  8. /**
  9.  * GreaterEqualCollationKey is a binary predicate that returns true
  10.  * if the first operand as a string is greater than or equal to the
  11.  * second operand as a string when compared using the given Collator object.
  12.  * Instead of using the compare() call, getCollationKey() is used and the
  13.  * results of that are compared.
  14.  * If either operand is itself a CollationKey object, then that operand is
  15.  * used without getting a new key from the collator.
  16.  * <p>
  17.  * If an explicit Collator object is not given, the default is used.
  18.  * <p>
  19.  * @see java.text.Collator
  20.  * @see java.text.CollationKey
  21.  * @see COM.objectspace.jgl.examples.CollateExamples
  22.  * @version 2.0.2
  23.  * @author ObjectSpace, Inc.
  24.  */
  25.  
  26. public final class GreaterEqualCollationKey implements BinaryPredicate
  27.   {
  28.   Collator collator;
  29.  
  30.   /**
  31.    * Construct a GreaterEqualCollationKey function object that uses the collator
  32.    * object for the current default locale to compare objects.
  33.    */
  34.   public GreaterEqualCollationKey()
  35.     {
  36.     collator = Collator.getInstance();
  37.     }
  38.  
  39.   /**
  40.    * Construct a GreaterEqualCollationKey function object that uses the given collator
  41.    * object to compare objects.
  42.    * @param collator The Collator object that is to be used for comparisons.
  43.    */
  44.   public GreaterEqualCollationKey( Collator collator )
  45.     {
  46.     this.collator = collator;
  47.     }
  48.  
  49.   /**
  50.    * Return true if the first operand is greater than or equal to the second operand.
  51.    * <STRONG>Note:</STRONG> CollationKeys created by different Collators can 
  52.    * not be compared.
  53.    * @see java.text.CollationKey#compareTo
  54.    * @param first The first operand.
  55.    * @param second The second operand.
  56.    * @return true if the sort key of the first operand is greater than or equal to that of the second.
  57.    */
  58.   public boolean execute( Object first, Object second )
  59.     {
  60.     CollationKey firstKey = first instanceof CollationKey
  61.       ? (CollationKey)first
  62.       : collator.getCollationKey( first.toString() );
  63.     CollationKey secondKey = second instanceof CollationKey
  64.       ? (CollationKey)second
  65.       : collator.getCollationKey( second.toString() );
  66.     return firstKey.compareTo( secondKey ) >= 0;
  67.     }
  68.   }
  69.