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

  1. // Copyright(c) 1996,1997 ObjectSpace, Inc.
  2. import com.objectspace.jgl.*;
  3. import com.objectspace.jgl.algorithms.*;
  4. import com.objectspace.jgl.predicates.*;
  5.  
  6. /**
  7.  * Counting provides algorithms for tabulating the elements of a container.
  8.  *
  9.  * @see com.objectspace.jgl.algorithms.Counting
  10.  * @version 3.0.0
  11.  * @author ObjectSpace, Inc.
  12.  */
  13.  
  14. public class Algorithms3
  15.   {
  16.   public static void main( String[] args )
  17.     {
  18.     SList list = new SList();
  19.     list.add( new Integer( -1 ) );
  20.     list.add( new Integer( 1 ) );
  21.     list.add( new Integer( -2 ) );
  22.     list.add( new Integer( 1 ) );
  23.     list.add( new Integer( -3 ) );
  24.     System.out.println( "list = " + list );
  25.  
  26.     Object value = new Integer( 1 );
  27.     int n1 = Counting.count( list, value );
  28.     System.out.println( "Occurences of " + value + " = " + n1 );
  29.  
  30.     int n2 = Counting.countIf( list, new NegativeNumber() );
  31.     System.out.println( "Occurences of a negative = " + n2 );
  32.     }
  33.   }
  34.