public class IntArray
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable
| Modifier and Type | Field and Description |
|---|---|
protected int[] |
data
Array data.
|
| Constructor and Description |
|---|
IntArray()
Constrcuts a new
IntArray instance with the default capacity. |
IntArray(int capacity)
Constrcuts a new
IntArray instance with the specified capacity. |
IntArray(int[] values)
Constrcuts a new
IntArray instance whose
capacity is the greater of the length of values and
DEFAULT_CAPACITY and whose initial contents are the specified
values. |
| Modifier and Type | Method and Description |
|---|---|
void |
add(int val)
Adds val to the end of the list, growing as needed.
|
void |
add(int[] vals)
Adds the values in the array vals to the end of the
list, in order.
|
void |
add(int[] vals,
int offset,
int length)
Adds a subset of the values in the array vals to the
end of the list, in order.
|
void |
clear()
Flushes the internal state of the list, resetting the capacity
to the default.
|
void |
clear(int capacity)
Flushes the internal state of the list, setting the capacity of
the empty list to capacity.
|
java.lang.Object |
clone()
Returns a clone of this list.
|
boolean |
contains(int value)
Searches the list for value
|
void |
ensureCapacity(int capacity)
Grow the internal array as needed to accomodate the specified
number of elements.
|
boolean |
equals(java.lang.Object other)
Compares this list to another list, value by value.
|
int |
get(int offset)
Returns the value at the specified offset.
|
int |
hashCode()
Returns the hash code value for this list.
|
void |
insert(int offset,
int value)
Inserts value into the list at offset.
|
void |
insert(int offset,
int[] values)
Inserts the array of values into the list at
offset.
|
void |
insert(int offset,
int[] values,
int valOffset,
int len)
Inserts a slice of the array of values into the list
at offset.
|
boolean |
isEmpty()
Tests whether this list contains any values.
|
int |
remove(int value)
Removes the element with value value from the list.
|
int |
removeAt(int offset)
Removes the value at offset from the list.
|
void |
removeAt(int offset,
int length)
Removes length values from the list, starting at
offset
|
void |
set(int offset,
int val)
Sets the value at the specified offset.
|
void |
set(int offset,
int[] values)
Replace the values in the list starting at offset with
the contents of the values array.
|
void |
set(int offset,
int[] values,
int valOffset,
int length)
Replace the values in the list starting at offset with
length values from the values array, starting
at valOffset.
|
int |
size()
Returns the number of values in the list.
|
int[] |
toArray()
Copies the contents of the list into a native array.
|
void |
toArray(int[] dest,
int offset,
int len)
Copies a slice of the list into a native array.
|
int[] |
toArray(int offset,
int len)
Copies a slice of the list into a native array.
|
java.lang.String |
toString()
Returns a String representation of the list, front to back.
|
void |
trimToSize()
Sheds any excess capacity above and beyond the current size of the list.
|
public IntArray()
IntArray instance with the default capacity.public IntArray(int capacity)
IntArray instance with the specified capacity.capacity - an int valuepublic IntArray(int[] values)
IntArray instance whose
capacity is the greater of the length of values and
DEFAULT_CAPACITY and whose initial contents are the specified
values.values - an int[] valuepublic void ensureCapacity(int capacity)
capacity - an int valuepublic int size()
public boolean isEmpty()
public void trimToSize()
public void add(int val)
val - an int valuepublic void add(int[] vals)
vals - an int[] valuepublic void add(int[] vals,
int offset,
int length)
vals - an int[] valueoffset - the offset at which to start copyinglength - the number of values to copy.public void insert(int offset,
int value)
offset - an int valuevalue - an int valuepublic void insert(int offset,
int[] values)
offset - an int valuevalues - an int[] valuepublic void insert(int offset,
int[] values,
int valOffset,
int len)
offset - an int valuevalues - an int[] valuevalOffset - the offset in the values array at which to
start copying.len - the number of values to copy from the values arraypublic int get(int offset)
offset - an int valueint valuepublic void set(int offset,
int val)
offset - an int valueval - an int valuepublic void set(int offset,
int[] values)
offset - the first offset to replacevalues - the source of the new valuespublic void set(int offset,
int[] values,
int valOffset,
int length)
offset - the first offset to replacevalues - the source of the new valuesvalOffset - the first value to copy from the values arraylength - the number of values to copypublic void clear()
public void clear(int capacity)
capacity - an int valuepublic int removeAt(int offset)
offset - an int valuepublic int remove(int value)
value - value of the element to be removedpublic void removeAt(int offset,
int length)
offset - an int valuelength - an int valuepublic java.lang.Object clone()
clone in class java.lang.Objectpublic int[] toArray()
int[] valuepublic int[] toArray(int offset,
int len)
offset - the offset at which to start copyinglen - the number of values to copy.int[] valuepublic void toArray(int[] dest,
int offset,
int len)
dest - the array to copy into.offset - the offset of the first value to copylen - the number of values to copy.public boolean equals(java.lang.Object other)
equals in class java.lang.Objectother - the object to compare againstpublic int hashCode()
This implementation uses exactly the code that is used to define the list hash function in the documentation for the List.hashCode method.
hashCode in class java.lang.Objectpublic boolean contains(int value)
value - an int valuepublic java.lang.String toString()
toString in class java.lang.ObjectString value