Applying2 Example Code
// Copyright(c) 1996 ObjectSpace, Inc.
import jgl.*;
/**
* Applying - inject a container with a given binary function
* which does a 'reduction' operation.
*
* @see jgl.Applying
* @version 1.1
* @author ObjectSpace, Inc.
*/
public class Applying2
{
public static void main( String[] args )
{
Array array = new Array();
array.add( new Integer( 100 ) );
array.add( new Integer( 2 ) );
array.add( new Integer( 71 ) );
System.out.println( "array = " + array );
System.out.println( "injecting TimesInteger(initial value==1) = "
+ Applying.inject( array.begin(), array.end(),
new Integer( 1 ), new TimesInteger() ) );
System.out.println( "injecting PlusInteger(initial value==0) = "
+ Applying.inject( array, new Integer( 0 ), new PlusInteger() ) );
System.out.println( "injecting MinusInteger(initial value==0) = "
+ Applying.inject( array, new Integer( 0 ), new MinusInteger() ) );
System.out.println( "injecting DividesInteger(initial value==1000) = "
+ Applying.inject( array, new Integer( 100000 ), new DividesInteger() ) );
}
}
Applying2 Example Output
array = Array( 100, 2, 71 )
injecting TimesInteger(initial value==1) = 14200
injecting PlusInteger(initial value==0) = 173
injecting MinusInteger(initial value==0) = -173
injecting DividesInteger(initial value==1000) = 7