//------------------------------------------------------------------------------ // GridList2D_Test.java //------------------------------------------------------------------------------ package tribble.util; import java.lang.ArrayIndexOutOfBoundsException; import java.lang.IllegalArgumentException; import java.lang.Integer; import java.lang.String; import java.lang.System; /******************************************************************************* * Test driver for class {@link GridList2D}. * * *
*
Source code:
*
* http://david.tribble.com/src/java/tribble/util/GridList2D_Test.java *
*
Documentation:
*
* http://david.tribble.com/docs/tribble/util/GridList2D_Test.html *
*
* * * @version $Revision: 1.1 $ $Date: 2010/10/20 22:37:16 $ * @since 2010-10-20 * @author David R. Tribble (david@tribble.com) *

* Copyright ©2010 by David R. Tribble, all rights reserved.
* Permission is granted to any person or entity except those designated by * by the United States Department of State as a terrorist, or terrorist * government or agency, to use and distribute this source code provided * that the original copyright notice remains present and unaltered.

*/ public class GridList2D_Test { static final String REV = "@(#)tribble/util/GridList2D_Test.java $Revision: 1.1 $ $Date: 2010/10/20 22:37:16 $\n"; // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // Constants public static final int RC_OKAY = 0; public static final int RC_USAGE = 255; // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ // Static methods /*************************************************************************** * Test driver for class {@link GridList2D}. * * @param args * Command line arguments. * * @since 1.1, 2010-10-20 */ public static void main(String[] args) { int cols; int elems; // Check command args if (args.length < 2) { // Display a usage message System.out.println("Test driver for class 'GridList2D'."); System.out.println(); System.out.println("usage: java " + GridList2D_Test.class.getName() + " cols elems"); // Punt System.exit(RC_USAGE); } // Parse the command line args cols = Integer.parseInt(args[0]); elems = Integer.parseInt(args[1]); test(cols, elems); // Done System.exit(RC_OKAY); } // private static void test(int cols, int elems) { GridList2D grid; boolean rowPrinted = true; // Create a 2D grid grid = new GridList2D(cols, elems); // Display a list of integers on the 2D grid for (int y = 0; rowPrinted; y++) { boolean printed = false; rowPrinted = false; for (int x = 0; x <= cols; x++) { int j; // Get the next 1D array index j = grid.indexFor(x, y); //if (j < 0) // break; // Display the 1D array element in the 2D grid System.out.printf("%4d", j); if (j >= 0) printed = true; } if (printed) System.out.println(); rowPrinted = printed; } System.out.println(); } } // End GridList2D_Test.java