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

  1. // Copyright(c) 1996 ObjectSpace, Inc.
  2. import jgl.*;
  3.  
  4. public class Algorithms9
  5.   {
  6.   public static void main( String[] args )
  7.     {
  8.     int ints1[] = { 1, 3, 5, 2 };
  9.     Array array = new Array();
  10.     IntArray intArray1 = new IntArray( ints1 );
  11.     UnaryFunction function = new NegateInteger();
  12.     Transforming.transform( intArray1, array, function );
  13.     System.out.println( "ints1 = " + intArray1 );
  14.     System.out.println( "array = " + array );
  15.     System.out.println();
  16.  
  17.     int ints2[] = { 2, 4, 2, 3 };
  18.     int ints3[] = { 3, 6, 2, 1 };
  19.     SList list = new SList();
  20.     IntArray intArray2 = new IntArray( ints2 );
  21.     IntArray intArray3 = new IntArray( ints3 );
  22.     BinaryFunction function2 = new TimesInteger();
  23.     Transforming.transform( intArray2, intArray3, list, function2 );
  24.     System.out.println( "ints2 = " + intArray2 );
  25.     System.out.println( "ints3 = " + intArray3 );
  26.     System.out.println( "list = " + list );
  27.     System.out.println();
  28.  
  29.     Array array1 = new Array();
  30.     array1.add( "cat" );
  31.     array1.add( "monkey" );
  32.     array1.add( "goat" );
  33.     System.out.println( "array1 = " + array1 );
  34.     Array array2 = (Array) Transforming.collect( array1, new LengthString() );
  35.     System.out.println( "array2 = " + array2 );
  36.     }
  37.   }
  38.  
  39.