Package openlink.util

## Class Vector

- java.lang.Object
- - openlink.util.Vector

Direct Known Subclasses:
  `VectorOfDouble`, `VectorOfFloat`, `VectorOfLong`

    public class Vector
    extends java.lang.Object

The Vector class is an implementation to store objects.

See Also:
  `Vector`

### Field Summary

Fields
`protected int` `capacityIncrement`
`protected int` `elementCount`
`protected java.lang.Object[]` `elementData`

### Constructor Summary

Constructors
`Vector​()` Constructs an empty vector.
`Vector​(int initialCapacity)` Constructs an empty vector with the specified initial capacity.
`Vector​(int initialCapacity, int capacityIncrement)` Constructs an empty vector with the specified initial capacity and capacity increment.
`Vector​(java.lang.Object[] array)` Constructs a vector from an array of objects.

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `addElement​(java.lang.Object obj)` Adds the specified component to the end of this vector, increasing its size by one.
`int` `capacity​()` Returns the current capacity of this vector.
`java.lang.Object` `clone​()`
`boolean` `contains​(java.lang.Object elem)` Tests if the specified object is a component in this vector.
`void` `copyInto​(java.lang.Object[] anArray)` Copies the components of this vector into the specified array.
`java.lang.Object` `elementAt​(int index)` Returns the component at the specified index.
`java.util.Enumeration` `elements​()` Returns an enumeration of the components of this vector.
`void` `ensureCapacity​(int minCapacity)` Increases the capacity of this vector, if necessary, to ensure that it can hold at least the number of components specified by the minimum capacity argument.
`java.lang.Object` `firstElement​()` Returns the first component of this vector.
`int` `indexOf​(java.lang.Object elem)` Searches for the first occurrence of the given argument, testing for equality using the `equals` method.
`int` `indexOf​(java.lang.Object elem, int index)` Searches for the first occurrence of the given argument, beginning the search at `index`, and testing for equality using the `equals` method.
`void` `insertElementAt​(java.lang.Object obj, int index)` Inserts the specified object as a component in this vector at the specified `index`.
`boolean` `isEmpty​()` Tests if this vector has no components.
`java.lang.Object` `lastElement​()` Returns the last component of the vector.
`int` `lastIndexOf​(java.lang.Object elem)` Returns the index of the last occurrence of the specified object in this vector.
`int` `lastIndexOf​(java.lang.Object elem, int index)` Searches backwards for the specified object, starting from the specified index, and returns an index to it.
`void` `removeAllElements​()` Removes all components from this vector and sets its size to zero.
`boolean` `removeElement​(java.lang.Object obj)` Removes the first occurrence of the argument from this vector.
`void` `removeElementAt​(int index)` Deletes the component at the specified index.
`void` `setElementAt​(java.lang.Object obj, int index)` Sets the component at the specified `index` of this vector to be the specified object.
`void` `setSize​(int newSize)` Sets the size of this vector.
`int` `size​()` Returns the number of components in this vector.
`java.lang.String` `toString​()` Returns a string representation of this vector.
`void` `trimToSize​()` Trims the capacity of this vector to be the vector's current size.

### Methods inherited from class java.lang.Object

`equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Field Detail

#### elementData

    protected java.lang.Object[] elementData

#### elementCount

    protected int elementCount

#### capacityIncrement

    protected int capacityIncrement

### Constructor Detail

#### Vector

    public Vector​(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

#### Vector

    public Vector​(int initialCapacity)

Constructs an empty vector with the specified initial capacity.

Parameters:
  `initialCapacity` - the initial capacity of the vector.

#### Vector

    public Vector​()

Constructs an empty vector.

#### Vector

    public Vector​(java.lang.Object[] array)

Constructs a vector from an array of objects.

Parameters:
  `array` - the array to copy into the vector.

### Method Detail

#### copyInto

    public void copyInto​(java.lang.Object[] anArray)

Copies the components of this vector into the specified array. The array must be big enough to hold all the objects in this vector.

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

#### trimToSize

    public void trimToSize​()

Trims the capacity of this vector to be the vector's current size. An application can use this operation to minimize the storage of a vector.

#### ensureCapacity

    public void ensureCapacity​(int minCapacity)

Increases the capacity of this vector, if necessary, to ensure that it can hold at least the number of components specified by the minimum capacity argument.

Parameters:
  `minCapacity` - the desired minimum capacity.

#### 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.
Since:
  JDK1.0

#### capacity

    public int capacity​()

Returns the current capacity of this vector.

Returns:
  the current capacity of this vector.

#### size

    public final int size​()

Returns the number of components in this vector.

Returns:
  the number of components in this vector.

#### isEmpty

    public boolean isEmpty​()

Tests if this vector has no components.

Returns:
  `true` if this vector has no components; `false` otherwise.

#### elements

    public java.util.Enumeration elements​()

Returns an enumeration of the components of this vector.

Returns:
  an enumeration of the components of this vector.
See Also:
  `Enumeration`

#### contains

    public boolean contains​(java.lang.Object elem)

Tests if the specified object is a component in this vector.

Parameters:
  `elem` - an object.
Returns:
  `true` if the specified object is a component in this vector; `false` otherwise.

#### indexOf

    public int indexOf​(java.lang.Object elem)

Searches for the first occurrence of the given argument, testing for equality using the `equals` method.

Parameters:
  `elem` - an object.
Returns:
  the index of the first occurrence of the argument in this vector; returns `-1` if the object is not found.
See Also:
  `Object.equals(java.lang.Object)`

#### indexOf

    public int indexOf​(java.lang.Object elem,
                       int index)

Searches for the first occurrence of the given argument, beginning the search at `index`, and testing for equality using the `equals` method.

Parameters:
  `elem` - an object.
  `index` - the index to start searching from.
Returns:
  the index of the first occurrence of the object argument in this vector at position `index` or later in the vector; returns `-1` if the object is not found.
See Also:
  `Object.equals(java.lang.Object)`

#### lastIndexOf

    public int lastIndexOf​(java.lang.Object elem)

Returns the index of the last occurrence of the specified object in this vector.

Parameters:
  `elem` - the desired component.
Returns:
  the index of the last occurrence of the specified object in this vector; returns `-1` if the object is not found.

#### lastIndexOf

    public int lastIndexOf​(java.lang.Object elem,
                           int index)

Searches backwards for the specified object, starting from the specified index, and returns an index to it.

Parameters:
  `elem` - the desired component.
  `index` - the index to start searching from.
Returns:
  the index of the last occurrence of the specified object in this vector at position less than `index` in the vector; `-1` if the object is not found.

#### elementAt

    public java.lang.Object elementAt​(int index)

Returns the component at the specified index.

Parameters:
  `index` - an index into this vector.
Returns:
  the component at the specified index.
Throws:
  `java.lang.ArrayIndexOutOfBoundsException` - if an invalid index was given.

#### firstElement

    public java.lang.Object firstElement​()

Returns the first component of this vector.

Returns:
  the first component of this vector.
Throws:
  `java.util.NoSuchElementException` - if this vector has no components.

#### lastElement

    public java.lang.Object lastElement​()

Returns the last component of the vector.

Returns:
  the last component of the vector, i.e., the component at index `size() - 1`.
Throws:
  `java.util.NoSuchElementException` - if this vector is empty.

#### 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.

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()`

#### 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 index must be a value greater than or equal to `0` and less than the current size of the vector.

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

#### 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.

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()`

#### 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.

Parameters:
  `obj` - the component to be added.

#### removeElement

    public boolean removeElement​(java.lang.Object obj)

Removes the first 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.

Parameters:
  `obj` - the component to be removed.
Returns:
  `true` if the argument was a component of this vector; `false` otherwise.

#### removeAllElements

    public void removeAllElements​()

Removes all components from this vector and sets its size to zero.

#### toString

    public java.lang.String toString​()

Returns a string representation of this vector.

Overrides:
  `toString` in class `java.lang.Object`
Returns:
  a string representation of this vector.

#### clone

    public java.lang.Object clone​()

Overrides:
  `clone` in class `java.lang.Object`