home *** CD-ROM | disk | FTP | other *** search
/ ActiveX Programming Unleashed CD / AXU.iso / jgl_1_1 / jgl_1_1.exe / examples / Applying2.java < prev    next >
Encoding:
Java Source  |  1996-09-13  |  1.3 KB  |  33 lines

  1. // Copyright(c) 1996 ObjectSpace, Inc.
  2.  
  3. import jgl.*;
  4.  
  5. /**
  6.  * Applying - inject a container with a given binary function
  7.  * which does a 'reduction' operation.
  8.  * <p>
  9.  * @see jgl.Applying
  10.  * @version 1.1
  11.  * @author ObjectSpace, Inc.
  12.  */
  13.  
  14. public class Applying2
  15.   {
  16.   public static void main( String[] args )
  17.     {                                                                   
  18.     Array array = new Array();
  19.     array.add( new Integer( 100 ) );
  20.     array.add( new Integer( 2 ) );
  21.     array.add( new Integer( 71 ) );
  22.     System.out.println( "array = " + array );
  23.     System.out.println( "injecting TimesInteger(initial value==1) = " 
  24.                         + Applying.inject( array.begin(), array.end(), 
  25.                                            new Integer( 1 ), new TimesInteger() ) );
  26.     System.out.println( "injecting PlusInteger(initial value==0) = " 
  27.                         + Applying.inject( array, new Integer( 0 ), new PlusInteger() ) );
  28.     System.out.println( "injecting MinusInteger(initial value==0) = " 
  29.                         + Applying.inject( array, new Integer( 0 ), new MinusInteger() ) );
  30.     System.out.println( "injecting DividesInteger(initial value==1000) = " 
  31.                         + Applying.inject( array, new Integer( 100000 ), new DividesInteger() ) );
  32.     }
  33.   }