marf.util
Class FreeVector

java.lang.Object
  extended by java.util.AbstractCollection
      extended by java.util.AbstractList
          extended by java.util.Vector
              extended by marf.util.FreeVector
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable, java.util.Collection, java.util.List, java.util.RandomAccess
Direct Known Subclasses:
Matrix

public class FreeVector
extends java.util.Vector

Adaptive extension of the java.util.Vector class.

You may access elements of a Vector beyond it's initial length --- the Vector will be automatically adjusted as appropriate.

Useful in the applications where desirable vector's growth by setting an element beyond its upper boundary automatically lengthens the vector to accommodate the change (similar to Perl arrays).

Similarly, getting an element beyond the upper boundary is not desirable failure, but an empty element returned. This makes the application to see as vector of a theoretically infinite in length.

TODO: allow negative index boundaries. $Id: FreeVector.java,v 1.13 2007/12/23 06:29:47 mokhov Exp $

Since:
0.3.0.1
Version:
$Revision: 1.13 $
Author:
Serguei Mokhov
See Also:
Serialized Form

Field Summary
private static long serialVersionUID
          For serialization versioning.
 
Fields inherited from class java.util.Vector
capacityIncrement, elementCount, elementData
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
FreeVector()
          A free vector with default capacity as specified by java.util.Vector.
FreeVector(java.util.Collection poCollection)
          Constructs this vector out of a collection.
FreeVector(int piInitialCapacity)
          Constructs this vector given capacity other than default.
FreeVector(int piInitialCapacity, int piCapacityIncrement)
          Constructs this vector given capacity and its increment.
 
Method Summary
 void add(int piIndex, java.lang.Object poElement)
          Adds an element of the vector at the specified index.
 boolean addAll(int piIndex, java.util.Collection poCollection)
          Adds a collection of elements to this vector starting at given index.
 java.lang.Object elementAt(int piIndex)
          Access an element of the vector given index.
 void ensureIndexCapacity(int piIndex)
          Make sure the capacity of the vector is enough to hold an element with the specified index.
 java.lang.Object get(int piIndex)
          Access an element of the vector given index.
static java.lang.String getMARFSourceCodeRevision()
          Retrieves class' revision.
 void insertElementAt(java.lang.Object poElement, int piIndex)
          Inserts an element of the vector after given index.
 java.lang.Object remove(int piIndex)
          Removes an element at index.
 void removeRange(int piFromIndex, int piToIndex)
          Not implemented.
 java.lang.Object set(int piIndex, java.lang.Object poElement)
          Set an element of the vector given index.
 void setElementAt(java.lang.Object poElement, int piIndex)
          Set an element of the vector given index.
 java.util.List subList(int piFromIndex, int piToIndex)
          Retrieves a sublist subset of vector elements given index boundaries.
 
Methods inherited from class java.util.Vector
add, addAll, addElement, capacity, clear, clone, contains, containsAll, copyInto, elements, ensureCapacity, equals, firstElement, hashCode, indexOf, indexOf, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, removeAll, removeAllElements, removeElement, removeElementAt, retainAll, setSize, size, toArray, toArray, toString, trimToSize
 
Methods inherited from class java.util.AbstractList
iterator, listIterator, listIterator
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
iterator, listIterator, listIterator
 

Field Detail

serialVersionUID

private static final long serialVersionUID
For serialization versioning. When adding new members or make other structural changes regenerate this number with the serialver tool that comes with JDK.

Since:
0.3.0.4
See Also:
Constant Field Values
Constructor Detail

FreeVector

public FreeVector()
A free vector with default capacity as specified by java.util.Vector.


FreeVector

public FreeVector(int piInitialCapacity)
Constructs this vector given capacity other than default. Inherited from java.util.Vector.

Parameters:
piInitialCapacity - initial element capacity (number of object placeholders)

FreeVector

public FreeVector(int piInitialCapacity,
                  int piCapacityIncrement)
Constructs this vector given capacity and its increment. Inherited from java.util.Vector.

Parameters:
piInitialCapacity - initial element capacity (number of object placeholders)
piCapacityIncrement - when current capacity reached, until how much capacity should be extended

FreeVector

public FreeVector(java.util.Collection poCollection)
Constructs this vector out of a collection. Inherited from java.util.Vector.

Parameters:
poCollection - collection for the vector elements.
Method Detail

elementAt

public java.lang.Object elementAt(int piIndex)
Access an element of the vector given index. Overridden from java.util.Vector.

Overrides:
elementAt in class java.util.Vector
Parameters:
piIndex - vector element index to retrieve
Returns:
object contained at specified index, null if beyond boundary

setElementAt

public void setElementAt(java.lang.Object poElement,
                         int piIndex)
Set an element of the vector given index. Capacity is always ensured to be able to accommodate any positive index (barring out of memory problems). Overridden from java.util.Vector.

Overrides:
setElementAt in class java.util.Vector
Parameters:
poElement - element to set at the index
piIndex - the index

insertElementAt

public void insertElementAt(java.lang.Object poElement,
                            int piIndex)
Inserts an element of the vector after given index. Capacity is always ensured to be able to accommodate any positive index (barring out of memory problems). Overridden from java.util.Vector.

Overrides:
insertElementAt in class java.util.Vector
Parameters:
poElement - element to set after the index
piIndex - the index

ensureIndexCapacity

public void ensureIndexCapacity(int piIndex)
Make sure the capacity of the vector is enough to hold an element with the specified index. Has effect only if the index is greater than the current vector's size.

Parameters:
piIndex - the index to accommodate

get

public java.lang.Object get(int piIndex)
Access an element of the vector given index. Overridden from java.util.Vector. Calls the overridden elementAt().

Specified by:
get in interface java.util.List
Overrides:
get in class java.util.Vector
Parameters:
piIndex - vector element index to retrieve
Returns:
object contained at specified index, null if beyond boundary

set

public java.lang.Object set(int piIndex,
                            java.lang.Object poElement)
Set an element of the vector given index. Capacity is always ensured to be able to accommodate any positive index (barring out of memory problems). Overridden from java.util.Vector.

Specified by:
set in interface java.util.List
Overrides:
set in class java.util.Vector
Parameters:
poElement - element to set at the index
piIndex - the index
Returns:
object that was previously at that index.

add

public void add(int piIndex,
                java.lang.Object poElement)
Adds an element of the vector at the specified index. Overridden from java.util.Vector. Calls the overridden insertElementAt().

Specified by:
add in interface java.util.List
Overrides:
add in class java.util.Vector
Parameters:
piIndex - the index
poElement - element to set after the index

remove

public java.lang.Object remove(int piIndex)
Removes an element at index. If the index is beyond the upper boundary, returns null. Overrides java.util.Vector.

Specified by:
remove in interface java.util.List
Overrides:
remove in class java.util.Vector
Parameters:
piIndex - index of the element to be removed
Returns:
object reference of the element just removed; null if index exceeds the upper bound

addAll

public boolean addAll(int piIndex,
                      java.util.Collection poCollection)
Adds a collection of elements to this vector starting at given index. Makes sure the capacity of the current vector reaches the piIndex. Overrides java.util.Vector.

Specified by:
addAll in interface java.util.List
Overrides:
addAll in class java.util.Vector
Parameters:
piIndex - starting index to add elements from
poCollection - collection of elements to add
Returns:
true if the vector has changed

subList

public java.util.List subList(int piFromIndex,
                              int piToIndex)
Retrieves a sublist subset of vector elements given index boundaries. Makes sure the capacity of the current vector reaches the piToIndex. Overrides java.util.Vector.

Specified by:
subList in interface java.util.List
Overrides:
subList in class java.util.Vector
Parameters:
piFromIndex - starting index to fetch elements from
piToIndex - last index to fetch elements to
Returns:
a corresponding List reference.

removeRange

public void removeRange(int piFromIndex,
                        int piToIndex)
Not implemented. Meant to remove a set of elements between two specified indices.

Overrides:
removeRange in class java.util.Vector
Parameters:
piFromIndex - starting index to remove elements from
piToIndex - last index to remove elements to
Throws:
NotImplementedException

getMARFSourceCodeRevision

public static java.lang.String getMARFSourceCodeRevision()
Retrieves class' revision.

Returns:
revision string
Since:
0.3.0.2


SourceForge Logo