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

  1. // Copyright(c) 1996,1997 ObjectSpace, Inc.
  2. import com.objectspace.jgl.*;
  3. import com.objectspace.jgl.adapters.*;
  4. import com.objectspace.jgl.algorithms.*;
  5. import com.objectspace.jgl.util.*;
  6.  
  7. /**
  8.  * Collapsing consecutive elements in a native array of Objects and an JGL container.
  9.  *
  10.  * @see com.objectspace.jgl.algorithms.Filtering
  11.  * @version 3.0.0
  12.  * @author ObjectSpace, Inc.
  13.  */
  14.  
  15. public class Filtering1
  16.   {
  17.   public static void main( String[] args )
  18.     {
  19.     String[] strings = { "gnu", "emu", "emu", "fox", "fox", "fox", "gnu" };
  20.     ObjectIterator begin = ObjectIterator.begin( strings );
  21.     ObjectIterator end = ObjectIterator.end( strings );
  22.     System.out.print( "strings = " );
  23.     Printing.println( begin, end );
  24.     ObjectIterator last = (ObjectIterator)Filtering.unique( begin, end );
  25.     System.out.print( "filtered strings = " );
  26.     Printing.println( begin, end );
  27.     int remaining = begin.distance( last );
  28.     System.out.println( "remaining = " + remaining );
  29.     System.out.print( "filtered array with bounds given = " );
  30.     end.retreat( remaining );
  31.     Printing.println( begin, end );
  32.  
  33.     Array array = new Array();
  34.     array.add( "gnu" );
  35.     array.add( "emu" );
  36.     array.add( "emu" );
  37.     array.add( "fox" );
  38.     array.add( "fox" );
  39.     array.add( "fox" );
  40.     array.add( "gnu" );
  41.     System.out.println( "array = " + array );
  42.     Deque deque = new Deque();
  43.     Filtering.uniqueCopy( array, new InsertIterator( deque ) );
  44.     System.out.println( "deque = " + deque );
  45.     }
  46.   }
  47.