ObjectSpace Homepage

JGL - The Generic Collection Library for Java
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Removing examples

Removing1 - Removing element from a container, conditional removal.

Removing2 - No description available.


Removing1 Example Code

// Copyright(c) 1996,1997 ObjectSpace, Inc.
import com.objectspace.jgl.*;
import com.objectspace.jgl.algorithms.*;
import com.objectspace.jgl.predicates.*;
import com.objectspace.jgl.util.*;

/**
 * Removing element from a container, conditional removal.
 *
 * @see com.objectspace.jgl.algorithms.Removing
 * @version 3.0.0
 * @author ObjectSpace, Inc.
 */

public class Removing1
  {
  public static void main( String[] args )
    {
    Array array = new Array();
    array.add( "ape" );
    array.add( "cat" );
    array.add( "dog" );
    array.add( "cat" );
    array.add( "emu" );
    System.out.println( "Before = " + array );
    Removing.remove( array, "cat" );
    System.out.println( "After = " + array );

    Deque deque = new Deque();
    deque.add( new Integer( 3 ) );
    deque.add( new Integer( 8 ) );
    deque.add( new Integer( 4 ) );
    deque.add( new Integer( 10 ) );
    DList result = new DList();
    UnaryPredicate predicate = new BindSecondPredicate( new LessNumber(), new Integer( 5 ) );
    Removing.removeCopyIf( deque, new InsertIterator( result ), predicate );
    System.out.println( "deque = " + deque + ", result = " + result );
    }
  }

Removing1 Example Output

Before = Array( ape, cat, dog, cat, emu )
After = Array( ape, dog, emu, cat, emu )
deque = Deque( 3, 8, 4, 10 ), result = DList( 8, 10 )

Removing2 Example Code

// Copyright(c) 1996,1997 ObjectSpace, Inc.
import com.objectspace.jgl.*;
import com.objectspace.jgl.algorithms.*;
import com.objectspace.jgl.predicates.*;

public class Removing2
  {
  public static void main( String[] args )
    {
    Deque deque = new Deque();
    deque.add( new Integer( 7 ) );
    deque.add( new Integer( 86 ) );
    deque.add( new Integer( 21 ) );
    deque.add( new Integer( 69 ) );
    System.out.println( "original=" + deque );

    UnaryPredicate predicate = new BindSecondPredicate( new LessNumber(), new Integer( 42 ) );
    ForwardIterator result = Removing.removeIf( deque, predicate );
    System.out.println( "after algo=" + deque );

    deque.remove( result, deque.finish() );
    System.out.println( "after remove=" + deque );
    }
  }

Removing2 Example Output

original=Deque( 7, 86, 21, 69 )
after algo=Deque( 86, 69, 21, 69 )
after remove=Deque( 86, 69 )

All Packages  Class Hierarchy  This Package  Previous  Next  Index