home *** CD-ROM | disk | FTP | other *** search
/ BUG 15 / BUGCD1998_06.ISO / aplic / jbuilder / jsamples.z / Collate2.java < prev    next >
Encoding:
Java Source  |  1997-07-30  |  1.4 KB  |  49 lines

  1. // Copyright(c) 1997 ObjectSpace, Inc.
  2.  
  3. import COM.objectspace.jgl.*;
  4. import java.text.Collator;
  5. import java.text.CollationKey;
  6. import java.util.Enumeration;
  7.  
  8. /**
  9.  * Comparison of CollationKeys.
  10.  *
  11.  * @see COM.objectspace.jgl.LessCollationKey
  12.  * @see COM.objectspace.jgl.LessEqualCollationKey
  13.  * @see COM.objectspace.jgl.GreaterCollationKey
  14.  * @see COM.objectspace.jgl.GreaterEqualCollationKey
  15.  * @see java.text.Collator
  16.  * @see java.text.CollationKey
  17.  * @version 2.0.2
  18.  * @author ObjectSpace, Inc.
  19.  */
  20.  
  21. public class Collate2
  22.   {
  23.   public static void show( String tag, Collator collator )
  24.     {
  25.     // allow duplicates in set
  26.     OrderedSet set = new OrderedSet( new LessCollationKey(), true );
  27.  
  28.     // add a few entries
  29.     set.add( collator.getCollationKey( "Texas" ) );
  30.     set.add( collator.getCollationKey( "texas" ) );
  31.     set.add( collator.getCollationKey( "Texas Fight" ) );
  32.  
  33.     // print the resulting container
  34.     System.out.println( tag );
  35.     Enumeration iterator = set.begin();
  36.     while ( iterator.hasMoreElements() )
  37.       System.out.println( "\t" + ( (CollationKey)iterator.nextElement() ).getSourceString() );
  38.     }
  39.  
  40.   public static void main( String args[] )
  41.     {
  42.     Collator collator = Collator.getInstance();
  43.     show( "default collating", collator );
  44.  
  45.     collator.setStrength( Collator.PRIMARY );
  46.     show( "case insensitive", collator );
  47.     }
  48.   }
  49.