jfun.util
Class IntArray

java.lang.Object
  extended by jfun.util.IntArray

public final class IntArray
extends java.lang.Object

A simple, efficient and dynamic int array.

Author:
Ben Yu.

Constructor Summary
IntArray()
          Create an IntArray object.
IntArray(int capacity)
          Create an IntArray object with an initial capacity.
 
Method Summary
 IntArray add(int i)
          Add a int into the array.
 void ensureCapacity(int capacity)
          Ensure that the IntArray has at least "l" capacity.
 int get(int i)
          Get the int value at a certain index.
 int set(int i, int val)
          Set the value at a certain index.
 int size()
          Get the number of int values stored.
 int[] toArray()
          Create a int[] object with all the elements stored in this IntArray.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IntArray

public IntArray(int capacity)
Create an IntArray object with an initial capacity.

Parameters:
capacity - the initial capacity.

IntArray

public IntArray()
Create an IntArray object.

Method Detail

toArray

public int[] toArray()
Create a int[] object with all the elements stored in this IntArray.

Returns:
the int[] object.

size

public int size()
Get the number of int values stored.


get

public int get(int i)
Get the int value at a certain index.

Parameters:
i - the 0-based index of the value.
Returns:
the int value.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if i is negative or >= size().

set

public int set(int i,
               int val)
Set the value at a certain index.

Parameters:
i - the 0-based index.
val - the new value.
Returns:
the old value.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if i is negative or >= size().

ensureCapacity

public void ensureCapacity(int capacity)
Ensure that the IntArray has at least "l" capacity.

Parameters:
capacity - the minimal capacity.

add

public IntArray add(int i)
Add a int into the array.

Parameters:
i - the int value.
Returns:
this IntArray object.