public class IntVector extends Object implements Serializable
java.util.Vector
, but elements are int
s. This is a
bare-bones implementation. May add features as I need them.Modifier and Type | Field and Description |
---|---|
protected int[] |
array |
protected int |
pos |
Constructor and 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.
|
Modifier and Type | Method and 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 end
|
void |
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 specified
int is a component of this IntVector . |
IntVector |
copy() |
void |
ensure_size(int req) |
boolean |
equals(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 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.
|
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 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 |
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() |
IntVector |
sortDedup() |
int[] |
toArray() |
int[] |
toArrayCopy() |
int[] |
toIntArray() |
String |
toString() |
void |
trimToSize()
Reduce the size of the internal array to the number of current elements.
|
public IntVector()
public IntVector(int[] array)
array
- The array the IntVector is initialized from.public IntVector(int capacity)
capacity
- Initial capacity of vector.public IntVector(int capacity, int growth_factor, int multiplication_limit)
capacity
- Initial capacity of vector.growth_factor
- Growth factor.multiplication_limit
- Multiplication limit.public void resetSize(int capacity)
public void setSize(int size)
public void add(int[] elements)
elements
- -public void addBulk(IntVector elements)
public void add(int[] elements, int startpos, int endpos)
elements
- -startpos
- -endpos
- -public void add(int element)
Vector
.element
- -public void multiAdd(int element, int count)
public void add(int index, int element)
0
-valued
elements are added.index
- -element
- -public void multiAdd(int index, int element, int count)
public void set(int index, int element)
index
- -element
- -public void put(int index, int element)
index
- -element
- -public int get(int index)
index
- -index
.ArrayIndexOutOfBoundsException
- If index
is not a valid index.public int remove(int index)
index
- The index of the element to be removed.index
.ArrayIndexOutOfBoundsException
- If index
is not a valid index.public void removeAllElements()
public void removeAllElementsAdjustSizeDown()
public boolean equals(Object o)
Object
with this IntVector
for equality.
Two IntVector
s 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()
.public int size()
public boolean contains(int elem)
int
is a component of this IntVector
.elem
- -true
if and only if the int
is an element of this
IntVector
, false
otherwise.public int position(int elem)
elem
in the IntVector, if it
exists.elem
- The element we're looking for.-1
if it doesn't exist.public void fill(int value)
value
- The fill value.public int[] toArray()
public IntVector sortDedup()
public int[] toArrayCopy()
public int[] getArray()
public int indexOf(int element)
element
- --1
if the element was not found.public int indexOfOptimizeAscending(int element)
element
- --1
if the element was not found.public void trimToSize()
public IntVector copy()
public int[] toIntArray()
public void ensure_size(int req)
Copyright © 2006–2018 The Apache Software Foundation. All rights reserved.