home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 October A / Pcwk10a98.iso / Inprise / TRIAL / JBUILDER / JSAMPLES.Z / Collate1.java < prev    next >
Text File  |  1998-05-08  |  1KB  |  47 lines

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