Package org.apache.uima.internal.util
Class IntVector
java.lang.Object
org.apache.uima.internal.util.IntVector
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
IntStack
Like
java.util.Vector
, but elements are int
s. This is a
bare-bones implementation. May add features as I need them.- See Also:
-
Field Summary
-
Constructor Summary
ConstructorDescriptionDefault 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
Modifier and TypeMethodDescriptionvoid
add
(int element) Add an element at the end of vector.void
add
(int[] elements) Add an array of elements to the end.void
add
(int[] elements, int startpos, int endpos) Add a slice of elements to the endvoid
add
(int index, int element) Add an element at a certain position in the vector.void
boolean
contains
(int elem) Tests if the specifiedint
is a component of thisIntVector
.copy()
void
copyFromArray
(int[] src, int srcPos, int destPos, int length) void
copyToArray
(int srcPos, int[] dest, int destPos, int length) void
ensure_size
(int req) boolean
Compares the specifiedObject
with thisIntVector
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 occurrence of the element specified in this vector.int
indexOfOptimizeAscending
(int element) Returns the index of some occurrence of the element specified in this vector. optimization: this is used only in bag index implementations or cases where which element among potentially many is picked, such as sets (at most one element) or "contains" (don't care which one is found) Other optimizations for that are done for the major use case that the order of adding elements results in the elements being more-or-less ordered, ascending.iterator()
int
lastIndexOf
(int element) void
multiAdd
(int element, int count) void
multiAdd
(int index, int element, int count) int
position
(int elem) Return the position of the first occurrence ofelem
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
Remove all elements and set size to 0.void
void
resetSize
(int capacity) void
set
(int index, int element) Set an element at a certain position in the vector.void
setSize
(int size) int
size()
void
sort()
int[]
toArray()
int[]
int[]
toString()
void
Reduce the size of the internal array to the number of current elements.
-
Field Details
-
pos
protected int pos
-
-
Constructor Details
-
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 Details
-
resetSize
public void resetSize(int capacity) -
setSize
public void setSize(int size) -
add
public void add(int[] elements) Add an array of elements to the end.- Parameters:
elements
- -
-
addBulk
-
add
public void add(int[] elements, int startpos, int endpos) Add a slice of elements to the end- Parameters:
elements
- -startpos
- -endpos
- -
-
add
public void add(int element) Add an element at the end of vector. Behaves like add(Object o) ofVector
.- Parameters:
element
- -
-
multiAdd
public void multiAdd(int element, int count) -
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, new0
-valued elements are added.- Parameters:
index
- -element
- -
-
multiAdd
public void multiAdd(int index, int element, int count) -
set
public void set(int index, int element) Set an element at a certain position in the vector.- Parameters:
index
- -element
- -
-
put
public void put(int index, int element) Set an element at a certain position in the vector. Vector will grow. Not apparently used (2014) Seems for purposes of having pairs of adjacent elements, (e.g. map).- Parameters:
index
- -element
- -
-
get
public int get(int index) Retrieve the element at index.- Parameters:
index
- -- Returns:
- The element at
index
. - Throws:
ArrayIndexOutOfBoundsException
- Ifindex
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:
ArrayIndexOutOfBoundsException
- Ifindex
is not a valid index.
-
removeAllElements
public void removeAllElements()Remove all elements and set size to 0. Will not change current capacity. -
removeAllElementsAdjustSizeDown
public void removeAllElementsAdjustSizeDown() -
equals
Compares the specifiedObject
with thisIntVector
for equality. TwoIntVector
s are equal if and only if the object passed ino
is of typeIntVector
,this.size() == o.size()
, and the n-th element in thisIntVector
is equal to the n-th element ino
for all n <this.size()
. -
size
public int size()- Returns:
- The number of elements in the vector.
-
contains
public boolean contains(int elem) Tests if the specifiedint
is a component of thisIntVector
.- Parameters:
elem
- -- Returns:
true
if and only if theint
is an element of thisIntVector
,false
otherwise.
-
position
public int position(int elem) Return the position of the first occurrence ofelem
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. Not used (2014)- Parameters:
value
- The fill value.
-
toArray
public int[] toArray()- Returns:
- the underlying int array, where the length of the returned array is equal to the vector's size. This is not a copy!
-
sortDedup
- Returns:
- an updated value for this vector, with the values sorted and duplicates removed
-
toArrayCopy
public int[] toArrayCopy()- Returns:
- a copy of the underlying array.
-
getArray
public int[] getArray()Return the internal array.- Returns:
- -
-
indexOf
public int indexOf(int element) Returns the index of the first occurrence of the element specified in this vector.- Parameters:
element
- -- Returns:
- the index or
-1
if the element was not found.
-
lastIndexOf
public int lastIndexOf(int element) -
indexOfOptimizeAscending
public int indexOfOptimizeAscending(int element) Returns the index of some occurrence of the element specified in this vector. optimization: this is used only in bag index implementations or cases where which element among potentially many is picked, such as sets (at most one element) or "contains" (don't care which one is found) Other optimizations for that are done for the major use case that the order of adding elements results in the elements being more-or-less ordered, ascending. Exploit this by assuming ascending, and testing if the element is above or below the mid-element, and ordering the direction of the search.- Parameters:
element
- -- 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
-
toIntArray
public int[] toIntArray()- Returns:
- a copy of the internal int array, trimmed
-
copyFromArray
public void copyFromArray(int[] src, int srcPos, int destPos, int length) -
copyToArray
public void copyToArray(int srcPos, int[] dest, int destPos, int length) -
toString
-
ensure_size
public void ensure_size(int req) -
hashCode
public int hashCode() -
iterator
-
intListIterator
-
sort
public void sort()
-