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

  1. // Copyright(c) 1996,1997 ObjectSpace, Inc.
  2. import com.objectspace.jgl.*;
  3. import com.objectspace.jgl.predicates.*;
  4.  
  5. /**
  6.  * Counting, finding, erasing.
  7.  *
  8.  * @see com.objectspace.jgl,OrderedMap
  9.  * @version 3.0.0
  10.  * @author ObjectSpace, Inc.
  11.  */
  12.  
  13. public class OrderedMap3
  14.   {
  15.   public static void main( String[] args )
  16.     {
  17.     OrderedMap map = new OrderedMap( new LessString() );
  18.     map.add( "cat", "Meow" );
  19.     map.add( "ape", "Squeak" );
  20.     map.add( "dog", "Woof" );
  21.     map.add( "bat", "Squeak" );
  22.     System.out.println( map );
  23.     System.out.println( "map.count( dog ) = " + map.count( "dog" ) );
  24.     OrderedMapIterator i = map.find( "dog" );
  25.     if ( i.equals( map.end() ) ) // A simpler way: if ( i.atEnd() ) ...
  26.       System.out.println( "Could not find dog." );
  27.     else
  28.       System.out.println( "Found " + i.get() );
  29.     System.out.println( "map.remove( dog ) = " + map.remove( "dog" ) );
  30.     OrderedMapIterator j = map.find( "dog" );
  31.     if ( j.atEnd() ) // A simpler way: if ( j.equals( map.end() ) ) ...
  32.       System.out.println( "Could not find dog." );
  33.     else
  34.       System.out.println( "Found " + j.get() );
  35.     }
  36.   }
  37.