FileDocCategorySizeDatePackage
Adapters3.javaAPI DocExample1996Sat Sep 12 03:01:00 BST 1998None

Adapters3

public class Adapters3 extends Object
Adapt a primitive array to algorithms and to a buffer.
see
com.objectspace.jgl.util.ArrayAdapter
version
3.0.0
author
ObjectSpace, Inc.

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

    // start with a native array
    float floats[] = { 3.0f, -1.1f, 2.0f, -3.1f, 4.0f };
    System.out.print( "native = " );
    Printing.println( FloatIterator.begin( floats ), FloatIterator.end( floats ) );

    // FloatArray affects the underlying array
    FloatArray floatArray = new FloatArray( floats );
    System.out.println( "Unsorted = " + floatArray );
    Sorting.sort( floatArray );
    System.out.println( "Sorted = " + floatArray );
    Shuffling.randomShuffle( floatArray );
    System.out.println( "Randomized = " + floatArray );
    System.out.print( "native = " );
    Printing.println( FloatIterator.begin( floats ), FloatIterator.end( floats ) );

    // FloatBuffer does not affect the underlying array
    FloatBuffer floatBuffer = new FloatBuffer( floats );
    System.out.println( "Unsorted = " + floatBuffer );
    Sorting.sort( floatBuffer );
    System.out.println( "Sorted = " + floatBuffer );
    Shuffling.randomShuffle( floatBuffer );
    System.out.println( "Randomized = " + floatBuffer );
    System.out.print( "native = " );
    Printing.println( FloatIterator.begin( floats ), FloatIterator.end( floats ) );

    // Buffers are growable
    floatBuffer.insert( 3, 5.6f );
    System.out.println( "Inserted = " + floatBuffer );
    floatBuffer.remove( 1, 3 );
    System.out.println( "Removed = " + floatBuffer );

    // and return to a native array
    floats = floatBuffer.get();
    System.out.print( "native = " );
    Printing.println( FloatIterator.begin( floats ), FloatIterator.end( floats ) );