org.apache.uima.internal.util
Class IntVector

java.lang.Object
  extended by org.apache.uima.internal.util.IntVector
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
IntStack

public class IntVector
extends java.lang.Object
implements java.io.Serializable

Like java.util.Vector, but elements are ints. This is a bare-bones implementation. May add features as I need them.

See Also:
Serialized Form

Field Summary
protected  int[] array
           
protected  int pos
           
 
Constructor Summary
IntVector()
          Default constructor.
IntVector(int capacity)
          Specify the initial capacity of this vector.
IntVector(int[] array)
          Construct an IntVector from an array.
IntVector(int capacity, int growth_factor, int multiplication_limit)
          Specify the initial capacity, growth factor and multiplication limit of this vector.
 
Method Summary
 void add(int element)
          Add an element at the end of vector.
 void add(int index, int element)
          Add an element at a certain position in the vector.
 boolean contains(int elem)
          Tests if the specified int is a component of this IntVector.
 IntVector copy()
           
 void ensure_size(int req)
           
 boolean equals(java.lang.Object o)
          Compares the specified Object with this IntVector for equality.
 void fill(int value)
          Set every element of the vector to some value.
 int get(int index)
          Retrieve the element at index.
 int[] getArray()
          Return the internal array.
 int hashCode()
           
 int indexOf(int element)
          Returns the index of the first occurence of the element specified in this vector.
 int position(int elem)
          Return the position of the first occurence of elem in the IntVector, if it exists.
 void put(int index, int element)
          Set an element at a certain position in the vector.
 int remove(int index)
          Remove the element at a certain index.
 void removeAllElements()
          Remove all elements and set size to 0.
 void set(int index, int element)
          Set an element at a certain position in the vector.
 void setSize(int size)
           
 int size()
           
 int[] toArray()
          Return the underlying int array, where the length of the returned array is equal to the vector's size.
 int[] toArrayCopy()
          Return a copy of the underlying array.
 java.lang.String toString()
           
 void trimToSize()
          Reduce the size of the internal array to the number of current elements.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

pos

protected int pos

array

protected int[] array
Constructor Detail

IntVector

public IntVector()
Default constructor.


IntVector

public IntVector(int[] array)
Construct an IntVector from an array. The array is not copied and may subsequently be modified.

Parameters:
array - The array the IntVector is initialized from.

IntVector

public IntVector(int capacity)
Specify the initial capacity of this vector. Use to avoid internal copying if you know ahead of time how large your vector is going to get (at least).

Parameters:
capacity - Initial capacity of vector.

IntVector

public IntVector(int capacity,
                 int growth_factor,
                 int multiplication_limit)
Specify the initial capacity, growth factor and multiplication limit of this vector. Use to avoid internal copying if you know ahead of time how large your vector is going to get (at least).

Parameters:
capacity - Initial capacity of vector.
growth_factor - Growth factor.
multiplication_limit - Multiplication limit.
Method Detail

setSize

public void setSize(int size)

add

public void add(int element)
Add an element at the end of vector. Behaves like add(Object o) of Vector.


add

public void add(int index,
                int element)
Add an element at a certain position in the vector. Elements later in the vector are shifted right by one. If the position is past the end of the current vector, new 0-valued elements are added.


set

public void set(int index,
                int element)
Set an element at a certain position in the vector.


put

public void put(int index,
                int element)
Set an element at a certain position in the vector. Vector will grow.


get

public int get(int index)
Retrieve the element at index.

Returns:
The element at index.
Throws:
java.lang.ArrayIndexOutOfBoundsException - If index is not a valid index.

remove

public int remove(int index)
Remove the element at a certain index.

Parameters:
index - The index of the element to be removed.
Returns:
The element at index.
Throws:
java.lang.ArrayIndexOutOfBoundsException - If index is not a valid index.

removeAllElements

public void removeAllElements()
Remove all elements and set size to 0. Will not change current capacity.


equals

public boolean equals(java.lang.Object o)
Compares the specified Object with this IntVector for equality. Two IntVectors are equal if and only if the object passed in o is of type IntVector, this.size() == o.size(), and the n-th element in this IntVector is equal to the n-th element in o for all n < this.size().

Overrides:
equals in class java.lang.Object
Returns:
true if the IntVectors are equal, false otherwise.

size

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

contains

public boolean contains(int elem)
Tests if the specified int is a component of this IntVector.

Returns:
true if and only if the int is an element of this IntVector, false otherwise.

position

public int position(int elem)
Return the position of the first occurence of elem in the IntVector, if it exists.

Parameters:
elem - The element we're looking for.
Returns:
The position, or -1 if it doesn't exist.

fill

public void fill(int value)
Set every element of the vector to some value.

Parameters:
value - The fill value.

toArray

public int[] toArray()
Return the underlying int array, where the length of the returned array is equal to the vector's size. This is not a copy!


toArrayCopy

public int[] toArrayCopy()
Return a copy of the underlying array.


getArray

public int[] getArray()
Return the internal array.


indexOf

public int indexOf(int element)
Returns the index of the first occurence of the element specified in this vector.

Returns:
the index or -1 if the element was not found.

trimToSize

public void trimToSize()
Reduce the size of the internal array to the number of current elements. You should only use this if you know that your vector will not grow anymore.


copy

public IntVector copy()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

ensure_size

public void ensure_size(int req)

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object


Copyright © 2011. All Rights Reserved.