mr3d.collections
Class DynamicStringArray

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

public class DynamicStringArray
extends java.lang.Object
implements Debugable

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

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

	DynamicStringArray myStrArray = new DynamicStringArray();	
									
	myStrArray.add("Hi");						
	System.out.println(myStrArray.get(0));		// "Hi"		
									
	myStrArray.replaceAt(0,"Hello");				
	System.out.println(myStrArray.get(0));		// "Hello"	
									
	myStrArray.add("World!");					
	System.out.println(myStrArray.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
DynamicStringArray()
          Creates a new dynamic String array.
 
Method Summary
 void add(java.lang.String newValue)
          Adds a new String-object with the specified value to the array.
 void appendAt(int index, java.lang.String appendix)
          Appends the String-object at the specified position with the given String-object.
 java.lang.String get(int index)
          Returns a String representation of the String object at the specified index.
 int indexOf(java.lang.String compareString)
          Returns the index of the first occurence.
 void removeAt(int index)
          Removes the String-object at the specified position.
 void replaceAt(int index, java.lang.String replacement)
          Replaces the String-object at the specified position with a new String-object.
 int size()
          Returns the the number of elements stored in the code>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

DynamicStringArray

public DynamicStringArray()
Creates a new dynamic String array.

Method Detail

add

public void add(java.lang.String newValue)
Adds a new String-object with the specified value to the array.

Parameters:
newValue - value to be added to the array

appendAt

public void appendAt(int index,
                     java.lang.String appendix)
Appends the String-object at the specified position with the given String-object.

Parameters:
index - position of the String-object to be extended
appendix - String-object that is to be appended to the original String

get

public java.lang.String get(int index)
Returns a String representation of the String object at the specified index. If the specefied index is invalid the method returns ERROR_STRING.

Parameters:
index - index of the value
Returns:
a String representation of the objects at the specified index out of bounds

indexOf

public int indexOf(java.lang.String compareString)
Returns the index of the first occurence.

Parameters:
compareString - the String object of which the index is to be returned
Returns:
index of the specified String object.

removeAt

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

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

replaceAt

public void replaceAt(int index,
                      java.lang.String replacement)
Replaces the String-object at the specified position with a new String-object.

Parameters:
index - position of the String value in the array
replacement - replacement String

size

public int size()
Returns the the number of elements stored in the code>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