com.isti.util
Class BufOrderedVector

java.lang.Object
  extended byjava.util.AbstractCollection
      extended byjava.util.AbstractList
          extended byjava.util.Vector
              extended bycom.isti.util.BufOrderedVector
All Implemented Interfaces:
java.lang.Cloneable, java.util.Collection, java.util.List, java.util.RandomAccess, java.io.Serializable

public class BufOrderedVector
extends java.util.Vector

Class BufOrderedVector is an extension of 'Vector' that supports specifying items to be returned last by the iterators.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.util.AbstractList
 
Field Summary
protected  java.lang.Object changeIterateLastListSyncObj
           
protected  java.util.List iterateLastList
           
protected  java.util.List iteratorBufList
           
 
Fields inherited from class java.util.Vector
capacityIncrement, elementCount, elementData
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
BufOrderedVector()
          Constructs an empty vector so that its internal data array has size 10 and its standard capacity increment is zero.
BufOrderedVector(java.util.Collection c)
          Constructs a vector containing the elements of the specified collection, in the order they are returned by the collection's iterator.
BufOrderedVector(int initialCapacity)
          Constructs an empty vector with the specified initial capacity and with its capacity increment equal to zero.
BufOrderedVector(int initialCapacity, int capacityIncrement)
          Constructs an empty vector with the specified initial capacity and capacity increment.
 
Method Summary
 boolean add(java.lang.Object o)
          Appends the specified element to the end of this Vector.
 boolean addAll(java.util.Collection c)
          Appends all of the elements in the specified Collection to the end of this Vector, in the order that they are returned by the specified Collection's Iterator.
 boolean addAll(int index, java.util.Collection c)
          Inserts all of the elements in in the specified Collection into this Vector at the specified position.
 void addElement(java.lang.Object obj)
          Adds the specified component to the end of this vector, increasing its size by one.
 void clearIterateLastList()
          Clears the iterate-last list.
 void copyInto(java.lang.Object[] anArray)
          Copies the components of this vector into the specified array.
 java.lang.Object getIterateLastListItem(int idx)
          Returns the item at the specified index in the iterate-last list.
 void insertElementAt(java.lang.Object obj, int index)
          Inserts the specified object as a component in this vector at the specified index.
 java.util.Iterator iterator()
          Returns an iterator over the elements in this list in proper sequence.
 java.util.ListIterator listIterator()
          Returns a list iterator of the elements in this list (in proper sequence).
 java.util.ListIterator listIterator(int index)
          Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list.
 java.lang.Object remove(int index)
          Removes the element at the specified position in this Vector.
 boolean removeAll(java.util.Collection c)
          Removes from this Vector all of its elements that are contained in the specified Collection.
 void removeAllElements()
          Removes all components from this vector and sets its size to zero.
 boolean removeElement(java.lang.Object obj)
          Removes the first (lowest-indexed) occurrence of the argument from this vector.
 void removeElementAt(int index)
          Deletes the component at the specified index.
 boolean retainAll(java.util.Collection c)
          Retains only the elements in this Vector that are contained in the specified Collection.
 java.lang.Object set(int index, java.lang.Object element)
          Replaces the element at the specified position in this Vector with the specified element.
 void setElementAt(java.lang.Object obj, int index)
          Sets the component at the specified index of this vector to be the specified object.
 void setIterateLastListItem(int idx, java.lang.Object itemObj)
          Enters the given item into the iterate-last list at the given position.
 void setSize(int newSize)
          Sets the size of this vector.
protected  void syncIteratorBufList()
          Synchronizes the buffered list for iterators.
 
Methods inherited from class java.util.Vector
add, capacity, clear, clone, contains, containsAll, elementAt, elements, ensureCapacity, equals, firstElement, get, hashCode, indexOf, indexOf, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, removeRange, size, subList, toArray, toArray, toString, trimToSize
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

iteratorBufList

protected java.util.List iteratorBufList

iterateLastList

protected java.util.List iterateLastList

changeIterateLastListSyncObj

protected final java.lang.Object changeIterateLastListSyncObj
Constructor Detail

BufOrderedVector

public BufOrderedVector(int initialCapacity,
                        int capacityIncrement)
Constructs an empty vector with the specified initial capacity and capacity increment.

Parameters:
initialCapacity - the initial capacity of the vector.
capacityIncrement - the amount by which the capacity is increased when the vector overflows.
Throws:
java.lang.IllegalArgumentException - if the specified initial capacity is negative.

BufOrderedVector

public BufOrderedVector(int initialCapacity)
Constructs an empty vector with the specified initial capacity and with its capacity increment equal to zero.

Parameters:
initialCapacity - the initial capacity of the vector.
Throws:
java.lang.IllegalArgumentException - if the specified initial capacity is negative

BufOrderedVector

public BufOrderedVector()
Constructs an empty vector so that its internal data array has size 10 and its standard capacity increment is zero.


BufOrderedVector

public BufOrderedVector(java.util.Collection c)
Constructs a vector containing the elements of the specified collection, in the order they are returned by the collection's iterator.

Parameters:
c - the collection whose elements are to be placed into this vector.
Method Detail

copyInto

public void copyInto(java.lang.Object[] anArray)
Copies the components of this vector into the specified array. The item at index k in this vector is copied into component k of anArray. The array must be big enough to hold all the objects in this vector, else an IndexOutOfBoundsException is thrown.

Parameters:
anArray - the array into which the components get copied.

setSize

public void setSize(int newSize)
Sets the size of this vector. If the new size is greater than the current size, new null items are added to the end of the vector. If the new size is less than the current size, all components at index newSize and greater are discarded.

Parameters:
newSize - the new size of this vector.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if new size is negative.

setElementAt

public void setElementAt(java.lang.Object obj,
                         int index)
Sets the component at the specified index of this vector to be the specified object. The previous component at that position is discarded.

The index must be a value greater than or equal to 0 and less than the current size of the vector.

This method is identical in functionality to the set method (which is part of the List interface). Note that the set method reverses the order of the parameters, to more closely match array usage. Note also that the set method returns the old value that was stored at the specified position.

Parameters:
obj - what the component is to be set to.
index - the specified index.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.
See Also:
Vector.size(), List, set(int, java.lang.Object)

removeElementAt

public void removeElementAt(int index)
Deletes the component at the specified index. Each component in this vector with an index greater or equal to the specified index is shifted downward to have an index one smaller than the value it had previously. The size of this vector is decreased by 1.

The index must be a value greater than or equal to 0 and less than the current size of the vector.

This method is identical in functionality to the remove method (which is part of the List interface). Note that the remove method returns the old value that was stored at the specified position.

Parameters:
index - the index of the object to remove.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.
See Also:
Vector.size(), remove(int), List

insertElementAt

public void insertElementAt(java.lang.Object obj,
                            int index)
Inserts the specified object as a component in this vector at the specified index. Each component in this vector with an index greater or equal to the specified index is shifted upward to have an index one greater than the value it had previously.

The index must be a value greater than or equal to 0 and less than or equal to the current size of the vector. (If the index is equal to the current size of the vector, the new element is appended to the Vector.)

This method is identical in functionality to the add(Object, int) method (which is part of the List interface). Note that the add method reverses the order of the parameters, to more closely match array usage.

Parameters:
obj - the component to insert.
index - where to insert the new component.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.
See Also:
Vector.size(), Vector.add(int, Object), List

addElement

public void addElement(java.lang.Object obj)
Adds the specified component to the end of this vector, increasing its size by one. The capacity of this vector is increased if its size becomes greater than its capacity.

This method is identical in functionality to the add(Object) method (which is part of the List interface).

Parameters:
obj - the component to be added.
See Also:
add(Object), List

removeElement

public boolean removeElement(java.lang.Object obj)
Removes the first (lowest-indexed) occurrence of the argument from this vector. If the object is found in this vector, each component in the vector with an index greater or equal to the object's index is shifted downward to have an index one smaller than the value it had previously.

This method is identical in functionality to the remove(Object) method (which is part of the List interface).

Parameters:
obj - the component to be removed.
Returns:
true if the argument was a component of this vector; false otherwise.
See Also:
List.remove(Object), List

removeAllElements

public void removeAllElements()
Removes all components from this vector and sets its size to zero.

This method is identical in functionality to the clear method (which is part of the List interface).

See Also:
Vector.clear(), List

set

public java.lang.Object set(int index,
                            java.lang.Object element)
Replaces the element at the specified position in this Vector with the specified element.

Parameters:
index - index of element to replace.
element - element to be stored at the specified position.
Returns:
the element previously at the specified position.
Throws:
java.lang.ArrayIndexOutOfBoundsException - index out of range (index < 0 || index >= size()).
java.lang.IllegalArgumentException - fromIndex > toIndex.

add

public boolean add(java.lang.Object o)
Appends the specified element to the end of this Vector.

Parameters:
o - element to be appended to this Vector.
Returns:
true (as per the general contract of Collection.add).

remove

public java.lang.Object remove(int index)
Removes the element at the specified position in this Vector. shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the Vector.

Parameters:
index - the index of the element to removed.
Throws:
java.lang.ArrayIndexOutOfBoundsException - index out of range (index < 0 || index >= size()).

addAll

public boolean addAll(java.util.Collection c)
Appends all of the elements in the specified Collection to the end of this Vector, in the order that they are returned by the specified Collection's Iterator. The behavior of this operation is undefined if the specified Collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified Collection is this Vector, and this Vector is nonempty.)

Parameters:
c - elements to be inserted into this Vector.
Throws:
java.lang.ArrayIndexOutOfBoundsException - index out of range (index < 0 || index > size()).

removeAll

public boolean removeAll(java.util.Collection c)
Removes from this Vector all of its elements that are contained in the specified Collection.

Returns:
true if this Vector changed as a result of the call.

retainAll

public boolean retainAll(java.util.Collection c)
Retains only the elements in this Vector that are contained in the specified Collection. In other words, removes from this Vector all of its elements that are not contained in the specified Collection.

Returns:
true if this Vector changed as a result of the call.

addAll

public boolean addAll(int index,
                      java.util.Collection c)
Inserts all of the elements in in the specified Collection into this Vector at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in the Vector in the order that they are returned by the specified Collection's iterator.

Parameters:
index - index at which to insert first element from the specified collection.
c - elements to be inserted into this Vector.
Throws:
java.lang.ArrayIndexOutOfBoundsException - index out of range (index < 0 || index > size()).

iterator

public java.util.Iterator iterator()
Returns an iterator over the elements in this list in proper sequence. This method references the buffered list.

Returns:
an iterator over the elements in this list in proper sequence.

listIterator

public java.util.ListIterator listIterator()
Returns a list iterator of the elements in this list (in proper sequence). This method references the buffered list.

Returns:
a list iterator of the elements in this list (in proper sequence).

listIterator

public java.util.ListIterator listIterator(int index)
Returns a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list. The specified index indicates the first element that would be returned by an initial call to the next method. An initial call to the previous method would return the element with the specified index minus one. This method references the buffered list.

Parameters:
index - index of first element to be returned from the list iterator (by a call to the next method).
Returns:
a list iterator of the elements in this list (in proper sequence), starting at the specified position in this list.
Throws:
java.lang.IndexOutOfBoundsException - if the index is out of range (index < 0 || index > size()).

syncIteratorBufList

protected final void syncIteratorBufList()
Synchronizes the buffered list for iterators. This method should be called anytime that this BufOrderedVector is modified.


setIterateLastListItem

public void setIterateLastListItem(int idx,
                                   java.lang.Object itemObj)
Enters the given item into the iterate-last list at the given position. If an item does not exist at the given position on the iterate-last list then the given item is added to the end of the list. A 'null' item parameter may be given to remove the current item at the given position. The iterate-last list specifies items that should be returned last when iterating over this BufOrderedVector. The first item in the iterate-last list will be the last item returned by this BufOrderedVector's iterator.

Parameters:
idx - index position for new item.
itemObj - item to enter, or 'null' to remove item at given index position.

getIterateLastListItem

public java.lang.Object getIterateLastListItem(int idx)
Returns the item at the specified index in the iterate-last list. The iterate-last list specifies items that should be returned last when iterating over this BufOrderedVector. The first item in the iterate-last list will be the last item returned by this BufOrderedVector's iterator.

Parameters:
idx - index position for the returned item.
Returns:
The specified item, or null if none exists at the given position.

clearIterateLastList

public void clearIterateLastList()
Clears the iterate-last list. The iterate-last list specifies items that should be returned last when iterating over this BufOrderedVector.