All Packages Class Hierarchy This Package Previous Next Index
Applying1 - Applying a unary function to every element of a sequence.
Applying2 - Applying - inject a container with a given binary function
Applying1 Example Code
// Copyright(c) 1996,1997 ObjectSpace, Inc.
import com.objectspace.jgl.*;
import com.objectspace.jgl.algorithms.*;
import com.objectspace.jgl.functions.*;
/**
* Applying a unary function to every element of a sequence.
*
* @see com.objectspace.jgl.algorithms.Applying
* @version 3.0.0
* @author ObjectSpace, Inc.
*/
public class Applying1
{
public static void main( String[] args )
{
Array array = new Array();
array.add( "cat" );
array.add( "dog" );
array.add( "emu" );
System.out.println( "array = " + array );
System.out.println( "Print each element to standard output" );
Applying.forEach( array.begin(), array.end(), new Print() );
System.out.println( "Print each element to standard output" );
Applying.forEach( array, new Print() );
}
}
array = Array( cat, dog, emu )
Print each element to standard output
cat
dog
emu
Print each element to standard output
cat
dog
emu
Applying2 Example Code
// Copyright(c) 1996,1997 ObjectSpace, Inc.
import com.objectspace.jgl.*;
import com.objectspace.jgl.algorithms.*;
import com.objectspace.jgl.functions.*;
/**
* Applying - inject a container with a given binary function
* which does a 'reduction' operation.
*
* @see com.objectspace.jgl.algorithms.Applying
* @version 3.0.0
* @author ObjectSpace, Inc.
*/
public class Applying2
{
public static void main( String[] args )
{
Array array = new Array();
array.add( new Integer( 100 ) );
array.add( new Integer( 2 ) );
array.add( new Integer( 71 ) );
System.out.println( "array = " + array );
System.out.println
(
"injecting TimesNumber(initial value==1) = "
+ Applying.inject
(
array.begin(),
array.end(),
new Integer( 1 ),
new TimesNumber()
)
);
System.out.println
(
"injecting PlusNumber(initial value==0) = "
+ Applying.inject( array, new Integer( 0 ), new PlusNumber() )
);
System.out.println
(
"injecting MinusNumber(initial value==0) = "
+ Applying.inject( array, new Integer( 0 ), new MinusNumber() )
);
System.out.println
(
"injecting DividesNumber(initial value==100000) = "
+ Applying.inject( array, new Integer( 100000 ), new DividesNumber() )
);
}
}
array = Array( 100, 2, 71 )
injecting TimesNumber(initial value==1) = 14200
injecting PlusNumber(initial value==0) = 173
injecting MinusNumber(initial value==0) = -173
injecting DividesNumber(initial value==100000) = 7
All Packages Class Hierarchy This Package Previous Next Index