home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 15
/
BUGCD1998_06.ISO
/
aplic
/
jbuilder
/
jsamples.z
/
Finding2.java
< prev
next >
Wrap
Text File
|
1997-07-30
|
1KB
|
43 lines
// Copyright(c) 1996,1997 ObjectSpace, Inc.
import COM.objectspace.jgl.*;
/**
* Finding objects that match a predicate.
*
* @see COM.objectspace.jgl.Finding
* @version 2.0.2
* @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;
}
}