de.infinityloop.util
Class GridBase

java.lang.Object
  extended by de.infinityloop.util.GridBase

public class GridBase
extends java.lang.Object

A helper object/container for a dynamically sized, two-dimensional grid storage container (table, two-dimensional array)

Version:
1.0
Author:
rC

Field Summary
protected  java.util.Hashtable grid
           
 
Constructor Summary
GridBase()
           
 
Method Summary
 java.lang.Object get(int x, int y)
          Get the object from cell (X,Y)
 int getDimensionX()
          Gets the current max grid dimension in x direction.
 int getDimensionY()
          Gets the current max grid dimension in y direction.
 java.util.Hashtable getGrid()
           
 java.lang.Object remove(int x, int y)
          Removes any element at the specified position.
 java.lang.Object set(int x, int y, java.lang.Object obj)
          Set an object into cell (X,Y)
 void setGrid(java.util.Hashtable grid)
           
 java.lang.String toString()
          Writes the grid to a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

grid

protected java.util.Hashtable grid
Constructor Detail

GridBase

public GridBase()
Method Detail

set

public java.lang.Object set(int x,
                            int y,
                            java.lang.Object obj)
                     throws java.lang.IndexOutOfBoundsException
Set an object into cell (X,Y)

Parameters:
x - 0-based index first dimension
y - 0-based index second dimension
obj - Object to store at (x,y)
Returns:
object previously at that location or null if there wasn't one
Throws:
java.lang.IndexOutOfBoundsException

get

public java.lang.Object get(int x,
                            int y)
                     throws java.lang.IndexOutOfBoundsException
Get the object from cell (X,Y)

Parameters:
x - 0-based index first dimension
y - 0-based index second dimension
Returns:
object at that location or null if there wasn't one
Throws:
java.lang.IndexOutOfBoundsException

getDimensionX

public int getDimensionX()
Gets the current max grid dimension in x direction.

Returns:
the current maximum grid value in x direction over all y elements

getDimensionY

public int getDimensionY()
Gets the current max grid dimension in y direction.

Returns:
the current maximum grid value in y direction over all x elements

remove

public java.lang.Object remove(int x,
                               int y)
Removes any element at the specified position.

Returns:
the element removed (or null, if there wasn't any)

getGrid

public java.util.Hashtable getGrid()
Returns:
Returns the grid.

setGrid

public void setGrid(java.util.Hashtable grid)
Parameters:
grid - The grid to set.

toString

public java.lang.String toString()
Writes the grid to a string.

Overrides:
toString in class java.lang.Object