class CompareTestInner3 // Fig 4.34, pg 132
{
public static void main( String [ ] args )
{
Object [
] rects = new Object[ 4 ];
rects[ 0
] = new SimpleRectangle( 1, 10 );
rects[ 1
] = new SimpleRectangle( 20, 1 );
rects[ 2
] = new SimpleRectangle( 4, 6 );
rects[ 3
] = new SimpleRectangle( 5, 5 );
System.out.println( "MAX WIDTH: " + findMax( rects, new
Comparator( )
{
public int compare( Object obj1, Object obj2 )
{
SimpleRectangle r1 = (SimpleRectangle) obj1;
SimpleRectangle r2 = (SimpleRectangle) obj2;
return( r1.getWidth() - r2.getWidth() );
}
}
) );
System.out.println( "MAX AREA: " + findMax( rects, new
Comparator( )
{
public int compare( Object obj1, Object obj2 )
{
SimpleRectangle r1 = (SimpleRectangle) obj1;
SimpleRectangle r2 = (SimpleRectangle) obj2;
return( r1.getWidth()*r1.getLength() -
r2.getWidth()*r2.getLength() );
}
}
) );
}
}