home *** CD-ROM | disk | FTP | other *** search
/ BUG 15 / BUGCD1998_06.ISO / aplic / jbuilder / jsamples.z / Applying2.java < prev    next >
Encoding:
Java Source  |  1997-07-30  |  1.3 KB  |  51 lines

  1. // Copyright(c) 1996,1997 ObjectSpace, Inc.
  2.  
  3. import COM.objectspace.jgl.*;
  4.  
  5. /**
  6.  * Applying - inject a container with a given binary function
  7.  * which does a 'reduction' operation.
  8.  *
  9.  * @see COM.objectspace.jgl.Applying
  10.  * @version 2.0.2
  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
  24.       (
  25.       "injecting TimesNumber(initial value==1) = "
  26.       + Applying.inject
  27.         (
  28.         array.begin(),
  29.         array.end(),
  30.         new Integer( 1 ),
  31.         new TimesNumber()
  32.         )
  33.       );
  34.     System.out.println
  35.       (
  36.       "injecting PlusNumber(initial value==0) = "
  37.       + Applying.inject( array, new Integer( 0 ), new PlusNumber() )
  38.       );
  39.     System.out.println
  40.       (
  41.       "injecting MinusNumber(initial value==0) = "
  42.       + Applying.inject( array, new Integer( 0 ), new MinusNumber() )
  43.       );
  44.     System.out.println
  45.       (
  46.       "injecting DividesNumber(initial value==100000) = "
  47.       + Applying.inject( array, new Integer( 100000 ), new DividesNumber() )
  48.       );
  49.     }
  50.   }
  51.