home *** CD-ROM | disk | FTP | other *** search
/ BUG 15 / BUGCD1998_06.ISO / aplic / jbuilder / jsamples.z / Finding2.java < prev    next >
Text File  |  1997-07-30  |  1KB  |  43 lines

  1. // Copyright(c) 1996,1997 ObjectSpace, Inc.
  2.  
  3. import COM.objectspace.jgl.*;
  4.  
  5. /**
  6.  * Finding objects that match a predicate.
  7.  *
  8.  * @see COM.objectspace.jgl.Finding
  9.  * @version 2.0.2
  10.  * @author ObjectSpace, Inc.
  11.  */
  12.  
  13. public class Finding2
  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( "Array has SOME string > 5 chars  == "
  26.                         + Finding.some( array, new Finding2UnaryPredicate() ) );
  27.     System.out.println( "Array has EVERY string > 5 chars == "
  28.                         + Finding.every( array, new Finding2UnaryPredicate() ) );
  29.     System.out.println( "1st Object in array > 5 chars    == "
  30.                         + Finding.detect( array, new Finding2UnaryPredicate() ) );
  31.     }
  32.   }
  33.  
  34. class Finding2UnaryPredicate implements UnaryPredicate
  35.   {
  36.   // return true if the length of the toString() is
  37.   // greater than 5.
  38.   public boolean execute( Object object )
  39.     {
  40.     return object.toString().length() > 5;
  41.     }
  42.   }
  43.