home *** CD-ROM | disk | FTP | other *** search
/ ActiveX Programming Unleashed CD / AXU.iso / jgl_1_1 / examples / algorithms5.java < prev    next >
Encoding:
Java Source  |  1996-09-11  |  852 b   |  26 lines

  1. // Copyright(c) 1996 ObjectSpace, Inc.
  2. import jgl.*;
  3.  
  4. public class Algorithms5
  5.   {
  6.   public static void main( String[] args )
  7.     {
  8.     Array array1 = new Array();
  9.     array1.add( "cat" );
  10.     array1.add( "monkey" );
  11.     array1.add( "goat" );
  12.     array1.add( "elephant" );
  13.     System.out.println( "array1 = " + array1 );
  14.  
  15.     // Predicate that returns true if a string is greater than 4 characters long.
  16.     UnaryPredicate predicate = new UnaryComposePredicate( new BindSecondPredicate( new GreaterInteger(), new Integer( 4 ) ), new LengthString() );
  17.  
  18.     Array array2 = (Array) Filtering.select( array1, predicate );
  19.     System.out.println( "strings with length > 4 = " + array2 );
  20.  
  21.     Array array3 = (Array) Filtering.reject( array1, predicate );
  22.     System.out.println( "strings with length <= 4 = " + array3 );
  23.     }
  24.   }
  25.  
  26.