home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-09-10 | 1.2 KB | 44 lines |
- // Copyright(c) 1996 ObjectSpace, Inc.
-
- import jgl.*;
-
- /**
- * Finding objects that match a predicate.
- * <p>
- * @see jgl.Finding
- * @version 1.1
- * @author ObjectSpace, Inc.
- */
-
- public class Finding2
- {
- public static void main( String[] args )
- {
- Array array = new Array();
- array.add( "cat" );
- array.add( "monkey" );
- array.add( "lion" );
- array.add( "armadillo" );
- array.add( "zebra" );
- System.out.println( "array = " + array );
-
- System.out.println( "Array has SOME string > 5 chars == "
- + Finding.some( array, new Finding2UnaryPredicate() ) );
- System.out.println( "Array has EVERY string > 5 chars == "
- + Finding.every( array, new Finding2UnaryPredicate() ) );
- System.out.println( "1st Object in array > 5 chars == "
- + Finding.detect( array, new Finding2UnaryPredicate() ) );
- }
- }
-
- class Finding2UnaryPredicate implements UnaryPredicate
- {
- // return true if the length of the toString() is
- // greater than 5.
- public boolean execute( Object object )
- {
- return object.toString().length() > 5;
- }
- }
-
-