home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 August / PC Plus SuperCD 50a Issue 142 (CD142a) (August 1998).iso / full / jbuild / setup / JBuilder / jsamples.z / Algorithms9.java < prev    next >
Encoding:
Java Source  |  1997-08-11  |  1.5 KB  |  46 lines

  1. // Copyright(c) 1996,1997 ObjectSpace, Inc.
  2. import COM.objectspace.jgl.*;
  3.  
  4. /**
  5.  * Transforming provides algorithms for modifying elements in a sequence.
  6.  *
  7.  * @see COM.objectspace.jgl.Transforming
  8.  * @version 2.0.2
  9.  * @author ObjectSpace, Inc.
  10.  */
  11.  
  12. public class Algorithms9
  13.   {
  14.   public static void main( String[] args )
  15.     {
  16.     int ints1[] = { 1, 3, 5, 2 };
  17.     Array array = new Array();
  18.     IntArray intArray1 = new IntArray( ints1 );
  19.     UnaryFunction function = new NegateNumber();
  20.     Transforming.transform( intArray1, array, function );
  21.     System.out.println( "ints1 = " + intArray1 );
  22.     System.out.println( "array = " + array );
  23.     System.out.println();
  24.  
  25.     int ints2[] = { 2, 4, 2, 3 };
  26.     int ints3[] = { 3, 6, 2, 1 };
  27.     SList list = new SList();
  28.     IntArray intArray2 = new IntArray( ints2 );
  29.     IntArray intArray3 = new IntArray( ints3 );
  30.     BinaryFunction function2 = new TimesNumber();
  31.     Transforming.transform( intArray2, intArray3, list, function2 );
  32.     System.out.println( "ints2 = " + intArray2 );
  33.     System.out.println( "ints3 = " + intArray3 );
  34.     System.out.println( "list = " + list );
  35.     System.out.println();
  36.  
  37.     Array array1 = new Array();
  38.     array1.add( "cat" );
  39.     array1.add( "monkey" );
  40.     array1.add( "goat" );
  41.     System.out.println( "array1 = " + array1 );
  42.     Array array2 = (Array) Transforming.collect( array1, new LengthString() );
  43.     System.out.println( "array2 = " + array2 );
  44.     }
  45.   }
  46.