FileDocCategorySizeDatePackage
Finding1.javaAPI DocExample1785Sat Sep 12 03:01:00 BST 1998None

Finding1

public class Finding1 extends Object
Finding a single element, conditional searching, finding consecutive elements.
see
com.objectspace.jgl.algorithms.Finding
version
3.0.0
author
ObjectSpace, Inc.

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

    Array array = new Array();
    array.add( "cat" );
    array.add( "dog" );
    array.add( "emu" );
    array.add( "dog" );
    array.add( "dog" );
    ArrayIterator i = array.begin();

    while ( true )
      {
      i = (ArrayIterator)Finding.find( i, array.end(), "dog" );
      if ( i.atEnd() ) // A simpler way: if ( i.equals( array.end() ) )...
        break;
      System.out.println
        ( 
        "iterator found " + i.get() + " at index " + i.index() 
        );
      i.advance();
      }

    int intArray[] = { 3, 6, 2, 1, 8, 9, 4, 5 };
    IntIterator j = (IntIterator)Finding.findIf
      ( 
      IntIterator.begin( intArray ), 
      IntIterator.end( intArray ), 
      new BindSecondPredicate( new GreaterNumber(), new Integer( 7 ) ) 
      );
    System.out.println
      ( 
      "First element > 7 is " + j.get() + " at index " + j.index() 
      );

    DList list = new DList();
    list.add( "cat" );
    list.add( "dog" );
    list.add( "emu" );
    list.add( "emu" );
    list.add( "dog" );
    DListIterator k = (DListIterator)Finding.adjacentFind( list, new com.objectspace.jgl.predicates.EqualTo() );
    System.out.println
      ( 
      "First consecutive sequence: " + k.get() + " at index " + k.index()
      );