home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-09-10 | 1.0 KB | 41 lines |
- // Copyright(c) 1996 ObjectSpace, Inc.
-
- import jgl.*;
-
- /**
- * Selecting and rejecting elements from a container
- * <p>
- * @see jgl.Filtering
- * @version 1.1
- * @author ObjectSpace, Inc.
- */
-
- public class Filtering2
- {
- 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( "Collecting strings > 5 chars == "
- + Filtering.select( array, new Filtering2UnaryPredicate() ) );
- System.out.println( "Rejecting strings > 5 chars == "
- + Filtering.reject( array, new Filtering2UnaryPredicate() ) );
- }
- }
-
- class Filtering2UnaryPredicate implements UnaryPredicate
- {
- // return true if the length of the toString() is
- // greater than 5.
- public boolean execute( Object object )
- {
- return object.toString().length() > 5;
- }
- }
-