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

  1. // Copyright(c) 1996 ObjectSpace, Inc.
  2.  
  3. import jgl.*;
  4.  
  5. /**
  6.  * Selecting and rejecting elements from a container
  7.  * <p>
  8.  * @see jgl.Filtering
  9.  * @version 1.1
  10.  * @author ObjectSpace, Inc.
  11.  */
  12.  
  13. public class Filtering2
  14.   {
  15.   public static void main( String[] args )
  16.     {
  17.     Array array = new Array();
  18.     array.add( "cat" );
  19.     array.add( "monkey" );
  20.     array.add( "lion" );
  21.     array.add( "armadillo" );
  22.     array.add( "zebra" );
  23.     System.out.println( "array = " + array );
  24.  
  25.     System.out.println( "Collecting strings > 5 chars  == " 
  26.                         + Filtering.select( array, new Filtering2UnaryPredicate() ) );
  27.     System.out.println( "Rejecting strings > 5 chars   == " 
  28.                         + Filtering.reject( array, new Filtering2UnaryPredicate() ) );
  29.     }
  30.   }
  31.  
  32. class Filtering2UnaryPredicate implements UnaryPredicate
  33.   {
  34.   // return true if the length of the toString() is
  35.   // greater than 5.
  36.   public boolean execute( Object object )
  37.     {
  38.     return object.toString().length() > 5;
  39.     }
  40.   }
  41.