home *** CD-ROM | disk | FTP | other *** search
/ BUG 15 / BUGCD1998_06.ISO / aplic / jbuilder / jsamples.z / Algorithms5.java < prev    next >
Encoding:
Java Source  |  1997-07-30  |  1.1 KB  |  37 lines

  1. // Copyright(c) 1996,1997 ObjectSpace, Inc.
  2. import COM.objectspace.jgl.*;
  3.  
  4. /**
  5.  * Filtering provides algorithms for creating a variation of a sequence.
  6.  *
  7.  * @see COM.objectspace.jgl.Filtering
  8.  * @version 2.0.2
  9.  * @author ObjectSpace, Inc.
  10.  */
  11.  
  12. public class Algorithms5
  13.   {
  14.   public static void main( String[] args )
  15.     {
  16.     Array array1 = new Array();
  17.     array1.add( "cat" );
  18.     array1.add( "monkey" );
  19.     array1.add( "goat" );
  20.     array1.add( "elephant" );
  21.     System.out.println( "array1 = " + array1 );
  22.  
  23.     // Predicate that returns true if a string is greater than 4 characters long.
  24.     UnaryPredicate predicate = new UnaryComposePredicate
  25.       (
  26.       new BindSecondPredicate( new GreaterNumber(), new Integer( 4 ) ),
  27.       new LengthString()
  28.       );
  29.  
  30.     Array array2 = (Array) Filtering.select( array1, predicate );
  31.     System.out.println( "strings with length > 4 = " + array2 );
  32.  
  33.     Array array3 = (Array) Filtering.reject( array1, predicate );
  34.     System.out.println( "strings with length <= 4 = " + array3 );
  35.     }
  36.   }
  37.