mr3d.collections
Class DynamicIntArray

java.lang.Object
  extended bymr3d.collections.DynamicIntArray
All Implemented Interfaces:
Debugable

public class DynamicIntArray
extends java.lang.Object
implements Debugable

The class DynamicIntArray is a wrapper for java.lang.Vector providing an easy way to handle a dynamic array of int values.

The following short example demontrates the usage of the dynamic int array wrapper.

	DynamicIntArray myDynArray = new DynamicIntArray();		
									
	myDynArray.add(100);						
	System.out.println(myDynArray.get(0));		// 100		
									
	myDynArray.replaceAt(0,200);					
	System.out.println(myDynArray.get(0));		// 200		
									
	myDynArray.add(300);						
	System.out.println(myDynArray.size());		// 2		
 

Since:
MR3Dv1.0
Version:
11-2004
Author:
Manuel Ruelke

Field Summary
private  java.util.Vector elements
          Vector containing the array data.
 
Fields inherited from interface mr3d.debug.Debugable
ERROR_INT, ERROR_STRING
 
Constructor Summary
DynamicIntArray()
          Creates a new dynamic int array.
 
Method Summary
 void add(int newValue)
          Adds a new Integer object with the specified value to the array.
 void clear()
          Deletes all elements of the array
 boolean contains(int nr)
          Returns "true" if the specified int-value is already in the array.
 int get(int index)
          Returns the int value of the Integer object at the specified index.
 int indexOf(int compareInt)
          Returns the index of the first occurence of the specified int value.
 void insertAt(int newValue, int index)
          Inserts the int value at the specified position.
 void removeAt(int index)
          Removes the Integer object at the specified position.
 void replaceAt(int index, int newValue)
          Replaces the int value at the specified position with a new value.
 int size()
          Returns the the number of elements stored in the elements vector.
 void toConsole()
          Prints the contents of the object to the Java console.
 void toConsole(java.lang.String msgString)
          Prints the contents of the object to the Java console together with an information string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

elements

private java.util.Vector elements
Vector containing the array data.

Constructor Detail

DynamicIntArray

public DynamicIntArray()
Creates a new dynamic int array.

Method Detail

add

public void add(int newValue)
Adds a new Integer object with the specified value to the array.

Parameters:
newValue - value to be added to the array

clear

public void clear()
Deletes all elements of the array


contains

public boolean contains(int nr)
Returns "true" if the specified int-value is already in the array.

Parameters:
nr - number to be checked for
Returns:
"true" if array contains the number, "false" if not

get

public int get(int index)
Returns the int value of the Integer object at the specified index. If the specified index is invalid the method returns ERRORVAL.

Parameters:
index - index of the value
Returns:
the Integer at the specified index

indexOf

public int indexOf(int compareInt)
Returns the index of the first occurence of the specified int value.

Parameters:
compareInt - the int value of which the index is to be returned
Returns:
index of the specified int

insertAt

public void insertAt(int newValue,
                     int index)
Inserts the int value at the specified position.

Parameters:
index - position of the int value in the array
newValue - value to be inserted at the specified position

removeAt

public void removeAt(int index)
Removes the Integer object at the specified position.

Parameters:
index - position of the Integer object to be removed

replaceAt

public void replaceAt(int index,
                      int newValue)
Replaces the int value at the specified position with a new value.

Parameters:
index - position of the int value in the array
newValue - replacement value for the value on the specified position

size

public int size()
Returns the the number of elements stored in the elements vector.

Returns:
size of the vector

toConsole

public void toConsole()
Description copied from interface: Debugable
Prints the contents of the object to the Java console. How the information will be displayed depends on what data the object contains. Depending on structure and contents every implementation of this function produces a different result on the console.

Specified by:
toConsole in interface Debugable

toConsole

public void toConsole(java.lang.String msgString)
Description copied from interface: Debugable
Prints the contents of the object to the Java console together with an information string. How the information will be displayed depends on what data the object contains. Depending on structure and contents every implementation of this function produces a different result on the console.

Specified by:
toConsole in interface Debugable