com.digi.config.util
Class Vector2

java.lang.Object
  extended bycom.digi.config.util.Vector2

public class Vector2
extends java.lang.Object

Vector2 implements a 2-columns vector object. The 2 columns contain a key and a value similiar to Hashtable, however the entries in a Vector2 object is ordered. Vector2 implements mixed interface definitions like Vector and Hashtable.

See Also:
Hashtable, Vector

Constructor Summary
Vector2()
          Constructs an empty vector.
Vector2(int initialCapacity)
          Constructs an empty Vector2 with the specified storage capacity.
Vector2(int initialCapacity, int capacityIncrement)
          Constructs an empty Vector2 with the specified storage capacity and specified capacity increment.
 
Method Summary
(package private)  void addElement(java.lang.Object inKey, java.lang.Object inVal)
          Adds the key/value pair as the last elements of the vector.
 int capacity()
          Returns the current capacity of the vector.
 void clear()
          Removes all key/value elements in the vector.
 boolean contains(java.lang.Object inVal)
          Returns true if the collection contains inVal element in the value column.
 boolean containsKey(java.lang.Object inKey)
          Returns true if the collection contains inKey element in the key column.
 java.util.Enumeration elements()
          Returns an enumeration of the value elements.
 void ensureCapacity(int minCapacity)
          Ensures that the vector has at lease the specified capacity.
 java.lang.Object get(java.lang.Object inKey)
          Gets the value object associated with the specified key in the vector.
 void insertElementAt(java.lang.Object inKey, java.lang.Object inVal, int index)
          Inserts an key/value pair elements at the specified index.
 boolean isEmpty()
          Returns true if the collection contains no values.
 java.lang.Object keyElementAt(int index)
          Returns the key element at the specified index.
 int keyIndexOf(java.lang.Object inKey)
          Searches for the specified key object, starting from the first position and returns and index to it.
 int keyLastIndexOf(java.lang.Object inKey)
          Searches backward for the specified key object, starting from the last position and returns and index to it.
 java.util.Enumeration keys()
          Returns an enumeration of the key elements.
 void put(java.lang.Object inKey, java.lang.Object inVal)
          Puts the specified value element into the vector, using the specified key.
 boolean removeElement(java.lang.Object inKey)
          Deletes the key/val elements that matches the inKey.
 void removeElementAt(int index)
          Deletes the key/val elements at the specified index.
 void setElementAt(java.lang.Object inKey, java.lang.Object inVal, int index)
          Sets the element at the specified index to be the sepcified key/value.
 void setSize(int newSize)
          Sets the size of the vector.
 int size()
          Returns the number of elements in the vector.
 java.lang.String toString()
           
 void trimToSize()
          Trims the vector's capacity down to size.
 java.lang.Object valueElementAt(int index)
          Returns the value element at the specified index.
 int valueIndexOf(java.lang.Object inVal)
          Searches for the specified value object, starting from the first position and returns and index to it.
 int valueLastIndexOf(java.lang.Object inVal)
          Searches backward for the specified value object, starting from the last position and returns and index to it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Vector2

public Vector2()
Constructs an empty vector.


Vector2

public Vector2(int initialCapacity)
Constructs an empty Vector2 with the specified storage capacity.

Parameters:
initialCapacity - initial storage capacity of the vector.

Vector2

public Vector2(int initialCapacity,
               int capacityIncrement)
Constructs an empty Vector2 with the specified storage capacity and specified capacity increment.

Parameters:
initialCapacity - initial storage capacity of the vector.
capacityIncrement - how much to increase the elemnt's size by.
Method Detail

addElement

final void addElement(java.lang.Object inKey,
                      java.lang.Object inVal)
Adds the key/value pair as the last elements of the vector.

Parameters:
inKey - the key object to insert at the specified position.
inVal - the value object to insert at the specified position.

capacity

public final int capacity()
Returns the current capacity of the vector.


clear

public final void clear()
Removes all key/value elements in the vector. The vector becomes empty.


contains

public final boolean contains(java.lang.Object inVal)
Returns true if the collection contains inVal element in the value column.

Parameters:
inVal - the value to search for.

containsKey

public final boolean containsKey(java.lang.Object inKey)
Returns true if the collection contains inKey element in the key column.

Parameters:
inKey - the key to search for.

elements

public final java.util.Enumeration elements()
Returns an enumeration of the value elements.


ensureCapacity

public final void ensureCapacity(int minCapacity)
Ensures that the vector has at lease the specified capacity.

Parameters:
minCapacity - the desired minimum capacity.

get

public final java.lang.Object get(java.lang.Object inKey)
Gets the value object associated with the specified key in the vector.

Parameters:
inKey - the key to search for.
Returns:
the value element for the specified key or null of the key is not defined.

insertElementAt

public final void insertElementAt(java.lang.Object inKey,
                                  java.lang.Object inVal,
                                  int index)
                           throws java.lang.ArrayIndexOutOfBoundsException
Inserts an key/value pair elements at the specified index. Elements with an index greater than or equal to the current index are moved up.

Parameters:
inKey - the key object to insert at the specified position.
inVal - the value object to insert at the specified position.
index - the specified index.
Throws:
java.lang.ArrayIndexOutOfBoundsException - If an invalid index was given.

isEmpty

public final boolean isEmpty()
Returns true if the collection contains no values.


keyElementAt

public final java.lang.Object keyElementAt(int index)
                                    throws java.lang.ArrayIndexOutOfBoundsException
Returns the key element at the specified index.

Parameters:
index - the index of the desired key object.
Throws:
java.lang.ArrayIndexOutOfBoundsException - If an invalid index was given.

keyIndexOf

public final int keyIndexOf(java.lang.Object inKey)
Searches for the specified key object, starting from the first position and returns and index to it.

Parameters:
inKey - the key object to search.
Returns:
the index of the key in the vector, or -1 if it was not found.

keyLastIndexOf

public final int keyLastIndexOf(java.lang.Object inKey)
Searches backward for the specified key object, starting from the last position and returns and index to it.

Parameters:
inKey - the key object to search.
Returns:
the index of the key in the vector, or -1 if it was not found.

keys

public final java.util.Enumeration keys()
Returns an enumeration of the key elements.


put

public final void put(java.lang.Object inKey,
                      java.lang.Object inVal)
Puts the specified value element into the vector, using the specified key. The value element can be retrieved by doing a get() with the same key. The key and the value element can not be null.

Parameters:
inKey - the specified key in the vector.
inVal - the value element to be put.

removeElement

public final boolean removeElement(java.lang.Object inKey)
Deletes the key/val elements that matches the inKey. If the inKey occurs more than once, only the first is removed. If the inKey is not an element, return false.

Parameters:
inKey - the key of the element to be deleted.
Returns:
true if elemnt was removed, otherwise returns false.

removeElementAt

public final void removeElementAt(int index)
                           throws java.lang.ArrayIndexOutOfBoundsException
Deletes the key/val elements at the specified index. Elements with an index greater than the current index are moved down.

Parameters:
index - the elements to remove
Throws:
java.lang.ArrayIndexOutOfBoundsException - If an invalid index was given.

setElementAt

public final void setElementAt(java.lang.Object inKey,
                               java.lang.Object inVal,
                               int index)
                        throws java.lang.ArrayIndexOutOfBoundsException
Sets the element at the specified index to be the sepcified key/value. The previous key/value pair at the index position is discarded.

Parameters:
inKey - the key object to set at the specified position.
inVal - the value object to set at the specified position.
index - the specified index.
Throws:
java.lang.ArrayIndexOutOfBoundsException - If an invalid index was given.

setSize

public final void setSize(int newSize)
Sets the size of the vector. If the size shrinks, the extra elements (at the end of the vector) are lost. If the size increases, the new elements are set to null.

Parameters:
newSize - the new size of the vector.

size

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


toString

public java.lang.String toString()

trimToSize

public final void trimToSize()
Trims the vector's capacity down to size.


valueElementAt

public final java.lang.Object valueElementAt(int index)
                                      throws java.lang.ArrayIndexOutOfBoundsException
Returns the value element at the specified index.

Parameters:
index - the index of the desired value object.
Throws:
java.lang.ArrayIndexOutOfBoundsException - If an invalid index was given.

valueIndexOf

public final int valueIndexOf(java.lang.Object inVal)
Searches for the specified value object, starting from the first position and returns and index to it.

Parameters:
inVal - the value object to search.
Returns:
the index of the value in the vector, or -1 if it was not found.

valueLastIndexOf

public final int valueLastIndexOf(java.lang.Object inVal)
Searches backward for the specified value object, starting from the last position and returns and index to it.

Parameters:
inVal - the value object to search.
Returns:
the index of the value in the vector, or -1 if it was not found.


Copyright © 2001-2002 Digi International. All Rights Reserved.