All Packages Class Hierarchy This Package Previous Next Index
Transforming1 - Transforming a single sequence, transforming a pair of sequences.
Transforming2 - Transforming - collect objects from a container
Transforming1 Example Code
// Copyright(c) 1996,1997 ObjectSpace, Inc.
import com.objectspace.jgl.*;
import com.objectspace.jgl.adapters.*;
import com.objectspace.jgl.algorithms.*;
import com.objectspace.jgl.functions.*;
import com.objectspace.jgl.util.*;
/**
* Transforming a single sequence, transforming a pair of sequences.
*
* @see com.objectspace.jgl.algorithms.Transforming
* @version 3.0.0
* @author ObjectSpace, Inc.
*/
public class Transforming1
{
public static void main( String[] args )
{
Deque deque = new Deque();
deque.add( new Integer( 5 ) );
deque.add( new Integer( 2 ) );
deque.add( new Integer( -2 ) );
System.out.println( "before = " + deque );
Transforming.transform( deque, deque.begin(), new BindSecond( new TimesNumber(), new Integer( 2 ) ) );
System.out.println( "doubled = " + deque );
int ints[] = { 3, 4, 1, 2 };
IntArray intArray = new IntArray( ints );
System.out.println( "original = " + intArray );
Array array = new Array();
Transforming.transform( intArray, new InsertIterator( array ), new NegateNumber() );
System.out.println( "negated = " + array );
DList list1 = new DList();
list1.add( "ape" );
list1.add( "dog" );
DList list2 = new DList();
list2.add( "1" );
list2.add( "2" );
System.out.println( "list1 = " + list1 + ", list2 = " + list2 );
Array result = new Array( 2 );
Transforming.transform( list1, list2, result.begin(), new PlusString() );
System.out.println( "result = " + result );
}
}
before = Deque( 5, 2, -2 )
doubled = Deque( 10, 4, -4 )
original = int[]( 3, 4, 1, 2 )
negated = Array( -3, -4, -1, -2 )
list1 = DList( ape, dog ), list2 = DList( 1, 2 )
result = Array( ape1, dog2 )
Transforming2 Example Code
// Copyright(c) 1996,1997 ObjectSpace, Inc.
import com.objectspace.jgl.*;
import com.objectspace.jgl.algorithms.*;
import com.objectspace.jgl.functions.*;
import com.objectspace.jgl.util.*;
/**
* Transforming - collect objects from a container
*
* @see com.objectspace.jgl.algorithms.Transforming
* @version 3.0.0
* @author ObjectSpace, Inc.
*/
public class Transforming2
{
public static void main( String[] args )
{
Array array = new Array();
array.add( "dog" );
array.add( "barking animal" );
array.add( "walking" );
DList dlist = new DList();
Copying.copy( array, new InsertIterator( dlist ) );
System.out.println( "array = " + array );
System.out.println( "dlist = " + dlist );
System.out.println();
System.out.println( "collect(array) = " + Transforming.collect( array.begin(), array.end(), new LengthString() ) );
System.out.println( "collect(dlist) = " + Transforming.collect( dlist, new LengthString() ) );
}
}
array = Array( dog, barking animal, walking )
dlist = DList( dog, barking animal, walking )
collect(array) = Array( 3, 14, 7 )
collect(dlist) = DList( 3, 14, 7 )
All Packages Class Hierarchy This Package Previous Next Index