home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 October A / Pcwk10a98.iso / Inprise / TRIAL / JBUILDER / JSAMPLES.Z / Applying2.java < prev    next >
Text File  |  1998-05-08  |  1KB  |  52 lines

  1. // Copyright(c) 1996,1997 ObjectSpace, Inc.
  2. import com.objectspace.jgl.*;
  3. import com.objectspace.jgl.algorithms.*;
  4. import com.objectspace.jgl.functions.*;
  5.  
  6. /**
  7.  * Applying - inject a container with a given binary function
  8.  * which does a 'reduction' operation.
  9.  *
  10.  * @see com.objectspace.jgl.algorithms.Applying
  11.  * @version 3.0.0
  12.  * @author ObjectSpace, Inc.
  13.  */
  14.  
  15. public class Applying2
  16.   {
  17.   public static void main( String[] args )
  18.     {
  19.     Array array = new Array();
  20.     array.add( new Integer( 100 ) );
  21.     array.add( new Integer( 2 ) );
  22.     array.add( new Integer( 71 ) );
  23.     System.out.println( "array = " + array );
  24.     System.out.println
  25.       (
  26.       "injecting TimesNumber(initial value==1) = "
  27.       + Applying.inject
  28.         (
  29.         array.begin(),
  30.         array.end(),
  31.         new Integer( 1 ),
  32.         new TimesNumber()
  33.         )
  34.       );
  35.     System.out.println
  36.       (
  37.       "injecting PlusNumber(initial value==0) = "
  38.       + Applying.inject( array, new Integer( 0 ), new PlusNumber() )
  39.       );
  40.     System.out.println
  41.       (
  42.       "injecting MinusNumber(initial value==0) = "
  43.       + Applying.inject( array, new Integer( 0 ), new MinusNumber() )
  44.       );
  45.     System.out.println
  46.       (
  47.       "injecting DividesNumber(initial value==100000) = "
  48.       + Applying.inject( array, new Integer( 100000 ), new DividesNumber() )
  49.       );
  50.     }
  51.   }
  52.