Package org.apache.uima.internal.util
Class IntVector
- java.lang.Object
-
- 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
Likejava.util.Vector
, but elements areint
s. This is a bare-bones implementation. May add features as I need them.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private int[]
array
private static int
default_growth_factor
private static int
default_multiplication_limit
private static int
default_size
private int
growth_factor
private int
multiplication_limit
protected int
pos
private static long
serialVersionUID
-
Constructor Summary
Constructors Constructor Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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
addBulk(IntVector elements)
boolean
contains(int elem)
Tests if the specifiedint
is a component of thisIntVector
.IntVector
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
equals(java.lang.Object o)
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.IntListIterator
intListIterator()
java.util.PrimitiveIterator.OfInt
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
removeAllElements()
Remove all elements and set size to 0.void
removeAllElementsAdjustSizeDown()
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()
IntVector
sortDedup()
int[]
toArray()
int[]
toArrayCopy()
int[]
toIntArray()
java.lang.String
toString()
void
trimToSize()
Reduce the size of the internal array to the number of current elements.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
default_size
private static final int default_size
- See Also:
- Constant Field Values
-
default_growth_factor
private static final int default_growth_factor
- See Also:
- Constant Field Values
-
default_multiplication_limit
private static final int default_multiplication_limit
- See Also:
- Constant Field Values
-
growth_factor
private final int growth_factor
-
multiplication_limit
private final int multiplication_limit
-
pos
protected int pos
-
array
private 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
-
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
public void addBulk(IntVector elements)
-
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:
java.lang.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:
java.lang.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
public boolean equals(java.lang.Object o)
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()
.- Overrides:
equals
in classjava.lang.Object
- Parameters:
o
- -- Returns:
true
if theIntVector
s 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 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
public IntVector 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
public IntVector 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
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
ensure_size
public void ensure_size(int req)
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
iterator
public java.util.PrimitiveIterator.OfInt iterator()
-
intListIterator
public IntListIterator intListIterator()
-
sort
public void sort()
-
-