home *** CD-ROM | disk | FTP | other *** search
/ ActiveX Programming Unleashed CD / AXU.iso / jgl_1_1 / examples / orderedmap7.java < prev    next >
Encoding:
Java Source  |  1996-09-10  |  1.2 KB  |  48 lines

  1. // Copyright(c) 1996 ObjectSpace, Inc.
  2.  
  3. import jgl.*;
  4.  
  5. /**
  6.  * Counting, finding, erasing. 
  7.  * <p>
  8.  * @see jgl.OrderedMap
  9.  * @version 1.1
  10.  * @author ObjectSpace, Inc.
  11.  */
  12.  
  13. public class OrderedMap7
  14.   {
  15.   public static void main( String[] args )
  16.     {
  17.     OrderedMap map = new OrderedMap( new LessString(), true );
  18.     map.add( "cat", "Meow" );
  19.     map.add( "ape", "Squeak" );
  20.     map.add( "ape", "Whoop" );
  21.     map.add( "bat", "Squeak" );
  22.     System.out.println( map );
  23.  
  24.     System.out.println( "map.count( ape ) = " + map.count( "ape" ) );
  25.     OrderedMapIterator i = map.find( "ape" );
  26.  
  27.     if( i.equals( map.end() ) ) // A simpler way of saying this is: if( i.atEnd() ) ...
  28.       {
  29.       System.out.println( "Could not find dog." );
  30.       }
  31.     else
  32.       {
  33.       while( i.key().equals( "ape" ) )
  34.         {
  35.         System.out.println( "Found " + i.get() ); 
  36.         i.advance();
  37.         }
  38.       }
  39.     System.out.println( "map.remove( ape ) = " + map.remove( "ape" ) );
  40.     OrderedMapIterator j = map.find( "ape" );
  41.     if( j.atEnd() ) // A simpler way of saying: if( j.equals( map.end() ) ) ...
  42.       System.out.println( "Could not find ape." );
  43.     else
  44.       System.out.println( "Found " + j.get() );
  45.     }
  46.   }
  47.  
  48.