All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class net.strandberg.util.DynArray

java.lang.Object
   |
   +----net.strandberg.util.DynArray

public class DynArray
extends Object
Class DynArray is a dynamic array that will grow when objects are added. There is no such thing as an "index out of bounds" when using the DynArray, the array always grows to include an index added. The internal representation is a contiguous array which means the DynArray is best suited for "dense indexes", i.e. most indexes should be occupied. The internal array also guarantees that accessing the DynArray by index is fast.

Version:
$Revision: 0.0 $
Author:
Mats Strandberg

Variable Index

 o defaultIncrementC
 o defaultInitialSizeC

Constructor Index

 o DynArray()
Constructs a dynamic array with the default initial size (32) and the default increment (32).
 o DynArray(int)
Constructs a dynamic array with initial size as given by the argument and the default increment (32).
 o DynArray(int, int)
Constructs a dynamic array with an initial size and increment as given by the arguments.

Method Index

 o add(int, Object)
Adds an object at the specified index.
 o elements()
Gets an enumeration that contains all valid objects of this array.
 o get(int)
Gets the object previously added at the given index.
 o main(String[])
Tests the class.

Variables

 o defaultInitialSizeC
 public static final short defaultInitialSizeC
 o defaultIncrementC
 public static final short defaultIncrementC

Constructors

 o DynArray
 public DynArray()
Constructs a dynamic array with the default initial size (32) and the default increment (32).

 o DynArray
 public DynArray(int initialSize)
Constructs a dynamic array with initial size as given by the argument and the default increment (32).

Parameters:
initialSize - the initial size of the array
 o DynArray
 public DynArray(int initialSize,
                 int increment)
Constructs a dynamic array with an initial size and increment as given by the arguments.

Parameters:
initialSize - the initial size of the array
increment - the increment when the array dynamically grows

Methods

 o main
 public static void main(String args[])
Tests the class.

 o add
 public void add(int index,
                 Object obj)
Adds an object at the specified index. If index is "out of bounds", the array will dynamically grow to the needed size. When growth is needed, the array will grow by a factor times the increment given at array creation. The factor is at least 1 and always large enough to place the given index "inside array bounds".

Parameters:
index - position in the dynamic array where the object should be added
obj - the object to be inserted in the array
 o get
 public Object get(int index)
Gets the object previously added at the given index.

Parameters:
index - the index in the array for which the corresponing object should be returned.
Returns:
the object at the given index, null if no object has been stored at the given index. This also means that null is returned if index is "out of bounds".
 o elements
 public Enumeration elements()
Gets an enumeration that contains all valid objects of this array. The enumeration will not contain null values, it only contains objects previously added by the add method. The object in the enumeration are in order of increasing index.

Returns:
an enumeration that can be used to iterate through the objects added to the dynamic array.

All Packages  Class Hierarchy  This Package  Previous  Next  Index