home *** CD-ROM | disk | FTP | other *** search
/ ActiveX Programming Unleashed CD / AXU.iso / jgl_1_1 / jgl_1_1.exe / examples / Algorithms1.java < prev    next >
Encoding:
Java Source  |  1996-09-12  |  810 b   |  31 lines

  1. // Copyright(c) 1996 ObjectSpace, Inc.
  2. import jgl.*;
  3.  
  4. public class Algorithms1
  5.   {
  6.   public static void main( String[] args )
  7.     {
  8.     Array array1 = new Array();
  9.     array1.add( "cat" );
  10.     array1.add( "monkey" );
  11.     array1.add( "goat" );
  12.     Applying.forEach( array1, new PrintFunction() );
  13.  
  14.     SList list = new SList();
  15.     list.add( new Integer( 3 ) );
  16.     list.add( new Integer( 7 ) );
  17.     list.add( new Integer( 4 ) );
  18.     Integer total = (Integer) Applying.inject( list, new Integer( 0 ), new PlusInteger() );
  19.     System.out.println( "list = " + list + ", total = " + total );
  20.     }
  21.   }
  22.  
  23. class PrintFunction implements UnaryFunction
  24.   {
  25.   public Object execute( Object object )
  26.     {
  27.     System.out.println( "PRINT " + object );
  28.     return null; // Not used.
  29.     }
  30.   }
  31.