|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectchemaxon.util.IntArray
The IntArray class implements an array of
integers. The size of an
IntArray can grow or shrink as needed to accommodate
adding and removing items after the IntArray has been created.
This class is optimized for the memory efficient storage of very large number of integers. The array is incremented in blocks, so no reallocations take place during the expansion of the array.
| Field Summary | |
static int |
DEFAULT_BLOCK_SIZE
The default block size (in integers) |
| Constructor Summary | |
IntArray()
Constructs an empty IntArray. |
|
IntArray(int blockSize)
Constructs an empty IntArray with the specified block size. |
|
| Method Summary | |
void |
add(int value)
Adds the specified component to the end of this IntArray, increasing its size by one. |
boolean |
addAll(IntArray other)
Appends all of the elements in the specified collection to the end of this vector, in the order that they are returned by the specified collection's iterator (optional operation). |
int |
capacity()
Returns the current capacity of this IntArray. |
void |
clear()
Sets the size to zero. |
boolean |
contains(int elem)
Tests if the specified object is a component in this IntArray. |
void |
copyInto(int[] array)
Copies the components of this IntArray into the specified array. |
void |
fill(int value)
Sets all array elemnts to a specified value. |
int |
get(int index)
Returns the component at the specified index. |
int |
indexOf(int elem)
Searches for the first occurence of the given argument. |
int |
indexOf(int value,
int index)
Searches for the first occurence of the given argument, beginning the search at index. |
int |
indexOfWithBinarySearch(int num)
Searches for the first occurence of the given number with binary search. |
boolean |
isEmpty()
Tests if this IntArray has no components. |
int |
lastIndexOf(int value)
Returns the index of the last occurrence of the specified value in this IntArray. |
int |
lastIndexOf(int elem,
int index)
Searches backwards for the specified object, starting from the specified index, and returns an index to it. |
static void |
main(java.lang.String[] args)
For testing. |
void |
set(int index,
int value)
Sets the element at the specified index of this
IntArray to be the specified value. |
void |
setSize(int newSize)
Sets the size of this IntArray. |
void |
setWithExpansion(int index,
int value)
Sets the element at the specified index of this
IntArray to be the specified value. |
int |
size()
Returns the number of components in this IntArray. |
void |
sort()
Sorts the elements in ascending order. |
int[] |
toArray()
Converts this IntArray to an integer array. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int DEFAULT_BLOCK_SIZE
| Constructor Detail |
public IntArray()
public IntArray(int blockSize)
blockSize - the amount by which the capacity is
incremented (number of integers)| Method Detail |
public void copyInto(int[] array)
array - the array into which the components get copied.public int[] toArray()
public void setSize(int newSize)
0 items are added to the end of
the IntArray. If the new size is less than the current size, all
components at index newSize and greater are discarded.
newSize - the new size of this IntArray.public int capacity()
public int size()
public boolean isEmpty()
true if this IntArray has no components;
false otherwise.public boolean contains(int elem)
elem - an object.
true if the specified object is a component in
this IntArray; false otherwise.public int indexOf(int elem)
elem - an object.
-1 if the object is not found.public int indexOfWithBinarySearch(int num)
sort() prior to
this call, otherwise an IllegalStateException is thrown.
num - the number to look for
-1 if the value is not found.
public int indexOf(int value,
int index)
index.
value - an object.index - the index to start searching from.
index or later in the
IntArray; returns -1 if the object is not found.public int lastIndexOf(int value)
value - the desired component.
-1 if the value is not found.
public int lastIndexOf(int elem,
int index)
elem - the desired component.index - the index to start searching from.
index in the IntArray;
-1 if the object is not found.public int get(int index)
index - an index into this IntArray.
java.lang.IndexOutOfBoundsException - if an invalid index was
given.
public void set(int index,
int value)
index of this
IntArray to be the specified value.
index - the index of the element.value - the new value.
java.lang.ArrayIndexOutOfBoundsException - if the index is out of range
(index < 0 || index >= size()).size()
public void setWithExpansion(int index,
int value)
index of this
IntArray to be the specified value. Increases the capacity
if the index is not less than the current array size.
index - the index of the element.value - the new value.
java.lang.ArrayIndexOutOfBoundsException - if the index is negativepublic void add(int value)
value - the element to be added.public void clear()
public boolean addAll(IntArray other)
other - IntArray whose elements are to be added to this vector.
add(int)public void fill(int value)
value - the valuepublic void sort()
public static void main(java.lang.String[] args)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||