All Packages Class Hierarchy Previous Next Index
Sequences 1 - No description available.
Sequences 2 - No description available.
Sequences 3 - No description available.
Sequences 4 - No description available.
Sequences 5 - No description available.
Sequences 6 - No description available.
Sequences 7 - No description available.
Sequences1 Example Code
// Copyright(c) 1996,1997 ObjectSpace, Inc.
import COM.objectspace.jgl.*;
public class Sequences1
{
public static void main( String[] args )
{
Array array = new Array();
array.pushBack( "bat" ); // Add to end of array.
array.add( "cat" ); // Synonym for pushBack().
array.pushFront( "ape" ); // Insert at beginning of array.
System.out.println( "array = " + array );
System.out.println();
System.out.println( "Demonstrate access" );
System.out.println( "array.at( 0 ) = " + array.at( 0 ) );
System.out.println( "array.front() = " + array.front() );
System.out.println( "array.at( 2 ) = " + array.at( 2 ) );
System.out.println( "array.back() = " + array.back() );
System.out.println( "array.put( 1, \"fox\" )" );
array.put( 1, "fox" );
System.out.println( "array = " + array );
array.popFront();
System.out.println( "After popFront() = " + array );
array.popBack();
System.out.println( "After popBack() = " + array );
}
}
array = Array( ape, bat, cat )
Demonstrate access
array.at( 0 ) = ape
array.front() = ape
array.at( 2 ) = cat
array.back() = cat
array.put( 1, "fox" )
array = Array( ape, fox, cat )
After popFront() = Array( fox, cat )
After popBack() = Array( fox )
Sequences2 Example Code
// Copyright(c) 1996,1997 ObjectSpace, Inc.
import COM.objectspace.jgl.*;
public class Sequences2
{
public static void main( String[] args )
{
Deque deque = new Deque();
deque.add( "ape" );
deque.add( "bat" );
deque.add( "cat" );
deque.add( "bat" );
deque.add( "bat" );
deque.add( "cat" );
System.out.println( "deque = " + deque );
System.out.println( "deque.count( bat ) = " + deque.count( "bat" ) );
int index = deque.indexOf( "bat" );
System.out.println( "deque.indexOf( bat ) = " + index );
deque.remove( index );
System.out.println( "After deque.remove( " + index + " ) = " + deque );
deque.replace( 0, 2, "bat", "BAT" );
System.out.println( "After deque.replace( 0, 2, bat, BAT ) = " + deque );
System.out.println( "deque.remove( cat ) = " + deque.remove( "cat" ) );
System.out.println( "After deque.remove( cat ) = " + deque );
}
}
deque = Deque( ape, bat, cat, bat, bat, cat )
deque.count( bat ) = 3
deque.indexOf( bat ) = 1
After deque.remove( 1 ) = Deque( ape, cat, bat, bat, cat )
After deque.replace( 0, 2, bat, BAT ) = Deque( ape, cat, BAT, bat, cat )
deque.remove( cat ) = 2
After deque.remove( cat ) = Deque( ape, BAT, bat )
Sequences3 Example Code
// Copyright(c) 1996,1997 ObjectSpace, Inc.
import COM.objectspace.jgl.*;
public class Sequences3
{
public static void main( String[] args )
{
DList list = new DList();
list.add( "bat" );
list.add( "cat" );
list.add( "dog" );
System.out.println( "list = " + list );
list.insert( 0, "ape" );
System.out.println( "After insert at begin = " + list );
list.insert( list.size(), "emu" );
System.out.println( "After insert at end = " + list );
list.insert( 3, 2, "fox" );
System.out.println( "After list.insert( 3, 2, fox ) = " + list );
}
}
list = DList( bat, cat, dog )
After insert at begin = DList( ape, bat, cat, dog )
After insert at end = DList( ape, bat, cat, dog, emu )
After list.insert( 3, 2, fox ) = DList( ape, bat, cat, fox, fox, dog, emu )
Sequences4 Example Code
// Copyright(c) 1996,1997 ObjectSpace, Inc.
import COM.objectspace.jgl.*;
public class Sequences4
{
public static void main( String[] args )
{
Array array = new Array();
System.out.print( "array = " + array + ", size = " + array.size() );
System.out.println( ", capacity = " + array.capacity() );
array.insert( 0, 9, "x" );
System.out.print( "array = " + array + ", size = " + array.size() );
System.out.println( ", capacity = " + array.capacity() );
for ( int i = 0; i < 2; i++ )
{
array.add( "x" ); // Causes reallocation of internal storage.
System.out.print( "array = " + array + ", size = " + array.size() );
System.out.println( ", capacity = " + array.capacity() );
}
array.ensureCapacity( 1000 ); // Force reallocation of internal storage.
System.out.print( "array = " + array + ", size = " + array.size() );
System.out.println( ", capacity = " + array.capacity() );
array.trimToSize(); // Reduce capacity to the minimum required.
System.out.print( "array = " + array + ", size = " + array.size() );
System.out.println( ", capacity = " + array.capacity() );
}
}
array = Array(), size = 0, capacity = 10
array = Array( x, x, x, x, x, x, x, x, x ), size = 9, capacity = 10
array = Array( x, x, x, x, x, x, x, x, x, x ), size = 10, capacity = 10
array = Array( x, x, x, x, x, x, x, x, x, x, x ), size = 11, capacity = 20
array = Array( x, x, x, x, x, x, x, x, x, x, x ), size = 11, capacity = 1000
array = Array( x, x, x, x, x, x, x, x, x, x, x ), size = 11, capacity = 11
Sequences5 Example Code
// Copyright(c) 1996,1997 ObjectSpace, Inc.
import COM.objectspace.jgl.*;
public class Sequences5
{
public static void main( String[] args )
{
String strings1[] = { "ape", "bat", "cat" };
Array array = new Array( strings1 );
System.out.print( "array = " + array + ", size = " + array.size() );
System.out.println( ", capacity = " + array.capacity() );
array.put( 2, "CAT" );
System.out.println( "array = " + array );
System.out.print( "Original = " );
for ( int i = 0; i < strings1.length; i++ )
System.out.print( strings1[ i ] + " " );
System.out.println();
array.add( "dog" ); // Forces reallocation of storage.
System.out.print( "array = " + array + ", size = " + array.size() );
System.out.println( ", capacity = " + array.capacity() );
System.out.print( "Original = " );
for ( int i = 0; i < strings1.length; i++ )
System.out.print( strings1[ i ] + " " );
System.out.println();
String string2[] = new String[ array.size() ];
array.copyTo( string2 ); // Copy contents of array into native array.
for ( int i = 0; i < string2.length; i++ )
System.out.print( string2[ i ] + " " );
System.out.println();
}
}
array = Array( ape, bat, cat ), size = 3, capacity = 3
array = Array( ape, bat, CAT )
Original = ape bat CAT
array = Array( ape, bat, CAT, dog ), size = 4, capacity = 6
Original = ape bat CAT
ape bat CAT dog
Sequences6 Example Code
// Copyright(c) 1996,1997 ObjectSpace, Inc.
import COM.objectspace.jgl.*;
public class Sequences6
{
public static void main( String[] args )
{
SList slist1 = new SList();
slist1.add( "D" );
slist1.add( "B" );
SList slist2 = new SList();
slist2.add( "E" );
slist2.add( "A" );
slist2.add( "C" );
System.out.println( "slist1 = " + slist1 + ", slist2 = " + slist2 );
// Insert the whole of slist2 in front of the 1st element of slist1.
slist1.splice( 0, slist2 );
System.out.println( "slist1 = " + slist1 + ", slist2 = " + slist2 );
// Move the 1st element to the end of the slist.
slist1.splice( 5, slist1, 0 );
System.out.println( "slist1 = " + slist1 + ", slist2 = " + slist2 );
// Move the 2nd and 3rd elements to be in front of the last element.
slist1.splice( 4, slist1, 1, 2 );
System.out.println( "slist1 = " + slist1 + ", slist2 = " + slist2 );
}
}
slist1 = SList( D, B ), slist2 = SList( E, A, C )
slist1 = SList( E, A, C, D, B ), slist2 = SList()
slist1 = SList( A, C, D, B, E ), slist2 = SList()
slist1 = SList( A, B, C, D, E ), slist2 = SList()
Sequences7 Example Code
// Copyright(c) 1996,1997 ObjectSpace, Inc.
import COM.objectspace.jgl.*;
public class Sequences7
{
public static void main( String[] args )
{
DList list = new DList();
list.add( "D" );
list.add( "C" );
list.add( "C" );
list.add( "B" );
list.add( "A" );
list.add( "A" );
System.out.println( "list = " + list );
list.unique();
System.out.println( "list = " + list );
list.reverse();
System.out.println( "list = " + list );
}
}
list = DList( D, C, C, B, A, A )
list = DList( D, C, B, A )
list = DList( A, B, C, D )
All Packages Class Hierarchy Previous Next Index