All Packages Class Hierarchy Previous Next Index
Container 1 - No description available.
Container 2 - No description available.
Container 3 - No description available.
Container 4 - No description available.
Container 5 - No description available.
Container 6 - No description available.
Container 7 - No description available.
Container 8 - No description available.
Container 9 - No description available.
Container 10 - No description available.
Container1 Example Code
// Copyright(c) 1996,1997 ObjectSpace, Inc.
import COM.objectspace.jgl.*;
public class Container1
{
public static void main( String[] args )
{
Array array = new Array();
array.add( "triangle" );
array.add( "square" );
array.add( "pentagon" );
array.add( "hexagon" );
System.out.println( "array = " + array );
System.out.println( "array.size() = " + array.size() );
System.out.println( "array.empty() = " + array.isEmpty() );
array.clear();
System.out.println( "after array is cleared..." );
System.out.println( "array.size() = " + array.size() );
System.out.println( "array.empty() = " + array.isEmpty() );
}
}
array = Array( triangle, square, pentagon, hexagon )
array.size() = 4
array.empty() = false
after array is cleared...
array.size() = 0
array.empty() = true
Container2 Example Code
// Copyright(c) 1996,1997 ObjectSpace, Inc.
import COM.objectspace.jgl.*;
import java.util.Enumeration;
public class Container2
{
public static void main( String[] args )
{
Array array = new Array();
array.add( "triangle" );
array.add( "square" );
array.add( "pentagon" );
array.add( "hexagon" );
Enumeration iterator = array.elements();
while ( iterator.hasMoreElements() )
System.out.println( iterator.nextElement() );
}
}
triangle
square
pentagon
hexagon
Container3 Example Code
// Copyright(c) 1996,1997 ObjectSpace, Inc.
import COM.objectspace.jgl.*;
public class Container3
{
public static void main( String[] args )
{
Array array1 = new Array();
array1.add( "triangle" );
array1.add( "square" );
array1.add( "pentagon" );
System.out.println( "array1 = " + array1 );
// Illustrate copy construction.
Array array2 = new Array( array1 );
System.out.println( "array2 = " + array2 );
System.out.println( "array1.equals( array2 ) = " + array1.equals( array2 ) );
// Illustrate assignment using copy().
Array array3 = new Array();
array3.add( "heptagon" );
array3.add( "octagon" );
System.out.println( "before copy, array3 = " + array3 );
array3.copy( array1 );
System.out.println( "after copy, array3 = " + array3 );
// Illustrate cloning.
Array array4 = (Array) array1.clone();
System.out.println( "array4 = " + array4 );
}
}
array1 = Array( triangle, square, pentagon )
array2 = Array( triangle, square, pentagon )
array1.equals( array2 ) = true
before copy, array3 = Array( heptagon, octagon )
after copy, array3 = Array( triangle, square, pentagon )
array4 = Array( triangle, square, pentagon )
Container4 Example Code
// Copyright(c) 1996,1997 ObjectSpace, Inc.
import COM.objectspace.jgl.*;
public class Container4
{
public static void main( String[] args )
{
Array array1 = new Array();
array1.add( "ape" );
array1.add( "bat" );
array1.add( "cat" );
Array array2 = new Array();
array2.add( "red" );
array2.add( "blue" );
// Illustrate swapping.
System.out.println( "array1 = " + array1 + ", array2 = " + array2 );
array1.swap( array2 );
System.out.println( "array1 = " + array1 + ", array2 = " + array2 );
}
}
array1 = Array( ape, bat, cat ), array2 = Array( red, blue )
array1 = Array( red, blue ), array2 = Array( ape, bat, cat )
Container5 Example Code
// Copyright(c) 1996,1997 ObjectSpace, Inc.
import COM.objectspace.jgl.*;
public class Container5
{
public static void main( String[] args )
{
Array Array = new Array();
Array.add( new Integer( 2 ) );
Array.add( new Boolean( false ) );
Array.add( new Character( 'x' ) );
Array.add( new Float( 3.14F ) );
System.out.println( "Array = " + Array );
}
}
Array = Array( 2, false, x, 3.14 )
Container6 Example Code
// Copyright(c) 1996,1997 ObjectSpace, Inc.
import COM.objectspace.jgl.*;
import Company;
public class Container6
{
public static void main( String[] args )
{
Company company1 = new Company( "ObjectSpace" );
Company company2 = new Company( "Sun Microsystems" );
HashMap headquarters = new HashMap();
headquarters.put( company1, "Texas" );
headquarters.put( company2, "California" );
String location = (String) headquarters.get( company1 );
System.out.println( "The headquarters of " + company1 + " are in " + location );
}
}
The headquarters of Company( ObjectSpace ) are in Texas
Container7 Example Code
// Copyright(c) 1996,1997 ObjectSpace, Inc.
import COM.objectspace.jgl.*;
public class Container7
{
public static void main( String[] args )
{
Array array = new Array();
array.add( "ape" );
array.add( "cat" );
try
{
Object object = array.at( 5 );
}
catch ( IndexOutOfBoundsException exception )
{
System.out.println( "Caught " + exception );
}
}
}
Caught java.lang.IndexOutOfBoundsException: Attempt to access index 5 when valid range is 0..1
Container8 Example Code
// Copyright(c) 1996,1997 ObjectSpace, Inc.
import COM.objectspace.jgl.*;
public class Container8
{
public static void main( String[] args )
{
Array array = new Array();
try
{
Object object = array.front();
}
catch ( InvalidOperationException exception )
{
System.out.println( "Caught " + exception );
}
}
}
Caught COM.objectspace.jgl.InvalidOperationException: Array is empty
Container9 Example Code
// Copyright(c) 1996,1997 ObjectSpace, Inc.
import COM.objectspace.jgl.*;
public class Container9
{
public static void main( String[] args )
{
try
{
Array array = new Array( -2 );
}
catch ( IllegalArgumentException exception )
{
System.out.println( "Caught " + exception );
}
}
}
Caught java.lang.IllegalArgumentException: Attempt to create an Array with a negative size
Container10 Example Code
// Copyright(c) 1996,1997 ObjectSpace, Inc.
import COM.objectspace.jgl.*;
public class Container10
{
public static void main( String[] args )
{
int ints[] = { 3, -1, 2, 0, -6 };
IntArray intArray = new IntArray( ints ); // Construct adapter class.
System.out.println( "unsorted native int array = " + intArray );
Sorting.sort( intArray ); // Sort native array.
System.out.print( "sorted = " );
for ( int i = 0; i < ints.length; i++ )
System.out.print( ints[ i ] + " " );
System.out.println();
}
}
unsorted native int array = int[]( 3, -1, 2, 0, -6 )
sorted = -6 -1 0 2 3
All Packages Class Hierarchy Previous Next Index