0;)
if (elements[i].Equals(element))
return i;
return -1;
}
/**
* Searches backwards for the specified object, starting from the
* specified index, and returns its index, or -1 if not found.
*
* @param element a object.
* @param index the non-negative index to start searching from.
* @exception ArgumentOutOfRangeException if index is invalid.
*/
public int LastIndexOf (object element, int index)
{
for (int i=index; i>=0; i--)
if (elements[i].Equals(element))
return i;
return -1;
}
/**
* Returns the component at the specified index. This method is
* identical in functionality to the Get method.
*
* @param index an index into this Vector.
* @exception ArgumentOutOfRangeException if the index is invalid.
*/
public object ElementAt (int index)
{
return elements[index];
}
/**
* Returns the first component (the element at index 0) of this Vector.
*
* @return the first component of this Vector.
* @exception ArgumentOutOfRangeException if this Vector is empty.
*/
public object FirstElement ()
{
return elements[0];
}
/**
* Returns the last component of the Vector.
*
* @return the last component of the Vector, i.e., the component at size() - 1.
* @exception ArgumentOutOfRangeException if this Vector is empty.
*/
public object LastElement ()
{
return elements[count-1];
}
/**
* Sets the component at the specified index of this Vector to be the
* specified object. The previous component at that position is lost.
*
* 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 except
* that the latter returns the old object that was stored at the specified
* position and it has its argument in a different order.
*
* @param element what the component is to be set to.
* @param index the specified index.
* @exception ArgumentOutOfRangeException if the index was invalid.
*/
public void SetElementAt (object element, int index)
{
Set(index,element);
}
/**
* 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(int) method
* except that the remove(int) method returns the old value that was
* stored at the specified position.
*
* @param index the index of the object to remove.
* @exception ArgumentOutOfRangeException if the index was invalid.
*/
public void RemoveElementAt (int index)
{
Remove(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(int, object)
* method except that the latter method reverses the order of the
* arguments, to match array usage more closely.
*
* @param element the element to insert.
* @param index where to insert the new component.
* @exception ArgumentOutOfRangeException if the index was invalid.
*/
public void InsertElementAt (object element, int index)
{
Add(index,element);
}
/**
* 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
* except that the latter returns a bool.
*
* @param element the component to be added.
*/
public void AddElement (object element)
{
Add(element);
}
/**
* Removes all components from this Vector.
* This method is identical in functionality to the Clear method.
*
*/
public void RemoveAllElements ()
{
count = 0;
}
/**
* Returns a clone of this Vector. The copy will contain a reference
* to a clone of the internal data array, not a reference to the
* original internal data array of this Vector object.
*
* @return a clone of this Vector.
*/
public object Clone ()
{
object[] newArray = new object[elements.Length];
for (int i=0; ijava.util.Vector API).
*/
public bool Add (object element)
{
if (count == elements.Length)
Grow();
elements[count++] = element;
return true;
}
/**
* Removes the first occurrence of the specified element. If this Vector
* does not contain the element, it is left unchanged.
*
* N.B.Because remove(object) is ambiguous, it is not
* supported for Vectors; its functionality is provided by
* removeIndex(int) and removeElement(object).
*
* @param element element to be removed from this Vector, if present.
* @return true if this Vector contained the specified element.
*/
public bool Remove (object element)
{
int i = 0;
for (i=0; iindex; i--)
elements[i] = elements[i-1];
elements[index] = element;
}
/**
* Removes the element at the specified position and shifts any
* subsequent elements to the left (subtracts one from their
* indices). Returns the element that was removed.
*
* @param index the index of the element to removed.
* @return the element that was at this index position.
* @exception ArgumentOutOfRangeException if index is out of range.
*/
public object Remove (int index)
{
object old = elements[index];
for (int i=index; i0;)
if (!Contains(a[i]))
return false;
return true;
}
/**
* Returns true if this Vector contains all of the elements in the
* specified Vector.
*
* @param v Vector of elements to be tested for membership.
* @return true if all the elements of the specified collection belong to this.
*/
public bool ContainsAll (Vector v)
{
foreach (object elt in v)
if (!Contains(elt))
return false;
return true;
}
/**
* Appends all of the elements in the specified array to the end of
* this Vector, in the order of the array.
*
* @param a array containing the elements to be inserted.
* @exception ClassCastException if the collection contains a non-number.
* @return true (following the java.util.Vector API).
*/
public bool AddAll (object[] a)
{
EnsureCapacity(count+a.Length);
for (int i=0; ijava.util.Vector API).
*/
public bool AddAll (Vector v)
{
int size = v.Count;
EnsureCapacity(count+size);
foreach (object elt in v)
elements[count++] = elt;
return true;
}
/**
* Removes from this Vector all of its elements that are contained
* in the specified array. Note that all occurrences of such elemeents
* are removed - not just the first.
*
* @param a array of elements to be removed.
* @return true if this Vector changed as a result of the call.
*/
public bool RemoveAll (object[] a)
{
Vector indices = new Vector();
for (int i=0; i0;)
if (elt.Equals(elements[i]))
indices.Add(i);
RemoveAllIndices(indices);
return !indices.IsEmpty;
}
/**
* Removes from this Vector the first occurrence of the elements
* that are contained in the specified array
*
* @param a array of elements to be removed.
* @return true if this Vector changed as a result of the call.
*/
public bool RemoveAllFirst (object[] a)
{
Vector indices = new Vector();
for (int i=0; i 0)
code <<= 1;
else
code >>= 1;
code ^= elements[i].GetHashCode();
shift = -shift;
}
return (int)code;
}
/**
* Returns a string representation of this Vector.
*
* @return a string representation of this collection.
*/
public override string ToString ()
{
StringBuilder buf = new StringBuilder("[");
string sep = "";
for (int i=0; i
* N.B. Note that this method is public, whereas - strangely
* enough, it is protected in the java.util.Vector API!
*
* @param fromIndex index of first element to be removed.
* @param toIndex index after last element to be removed.
*/
public void RemoveRange (int fromIndex, int toIndex)
{
if (toIndex <= fromIndex)
return;
toIndex = Math.Min(toIndex, count);
int gap = toIndex - fromIndex;
for (int i=fromIndex; i 5.0)
throw new System.ArgumentException("Increment factor "+incFactor
+" must be in [1.1,5.0] range");
this.incFactor = incFactor;
}
// PRIVATES:
/**
* A constructor used privately for cloning only...
*/
private Vector (object[] elements, int count, int deltaCap, float incFactor)
{
this.elements = elements;
this.count = count;
this.deltaCap = deltaCap;
this.incFactor = incFactor;
}
/**
* Grows the size of the internal array.
*/
private void Grow ()
{
object[] newArray = new object[IncreasedCapacity()];
for (int i=0; i