com.vodafone360.people.utils
Class DynamicArrayLong

java.lang.Object
  extended by com.vodafone360.people.utils.DynamicArrayLong

public class DynamicArrayLong
extends java.lang.Object

This class wraps the long primitive array into a dynamic array that can grows if necessary.


Field Summary
private static int INITIAL_CAPACITY
          The initial capacity if not given via the constructor.
private  long[] mArray
          The wrapped long array.
private  int mIndex
          The current index where the next item will be added in the array.
 
Constructor Summary
DynamicArrayLong()
          Constructor.
DynamicArrayLong(int capacity)
          Constructor.
 
Method Summary
 int add(long value)
          Appends a value to the array.
 int add(long[] values)
          Adds the provided array.
 long get(int position)
          Gets the value from its given position in the array.
 int size()
          Gets the size of the array (i.e. the count of added values)
 long[] toArray()
          Gets an array of long containing all the values inside the DynamicArrayLong.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INITIAL_CAPACITY

private static final int INITIAL_CAPACITY
The initial capacity if not given via the constructor.

See Also:
Constant Field Values

mArray

private long[] mArray
The wrapped long array.


mIndex

private int mIndex
The current index where the next item will be added in the array.

Constructor Detail

DynamicArrayLong

public DynamicArrayLong()
Constructor.


DynamicArrayLong

public DynamicArrayLong(int capacity)
                 throws java.lang.IllegalArgumentException
Constructor.

Parameters:
capacity - the initial capacity of the array
Throws:
java.lang.IllegalArgumentException
Method Detail

add

public int add(long value)
Appends a value to the array. The values are added from index=0 and after each other. If the array is full, its size is increased so that the value can be added.

Parameters:
value - the value to add
Returns:
the position in the array where the value was set

add

public int add(long[] values)
Adds the provided array.

Parameters:
values - the array to be added
Returns:
the index of the last added value or -1 if nothing was added

get

public long get(int position)
         throws java.lang.ArrayIndexOutOfBoundsException
Gets the value from its given position in the array.

Parameters:
position - the position of the value in the array
Returns:
the value at the provided position
Throws:
java.lang.ArrayIndexOutOfBoundsException - if position not >=0 and < size()

size

public int size()
Gets the size of the array (i.e. the count of added values)

Returns:
the array size

toArray

public long[] toArray()
Gets an array of long containing all the values inside the DynamicArrayLong.

Returns:
an array with all the values or null if empty


JavaDoc