Nux 1.6

nux.xom.binary
Class ArrayIntList

java.lang.Object
  extended by nux.xom.binary.ArrayIntList

public final class ArrayIntList
extends Object

Efficient resizable auto-expanding list holding int elements; implemented with arrays.

Author:
whoschek.AT.lbl.DOT.gov, $Author: hoschek3 $

Constructor Summary
ArrayIntList()
          Constructs an empty list.
ArrayIntList(int initialCapacity)
          Constructs an empty list with the specified initial capacity.
 
Method Summary
 void add(int elem)
          Appends the specified element to the end of this list.
 void add(int[] elems, int offset, int length)
          Appends the elements in the range [offset..offset+length) to the end of this list.
 int[] asArray()
          Returns the elements currently stored, including invalid elements between size and capacity, if any.
 void clear()
          Removes all elements but keeps the current capacity; Afterwards size() will yield zero.
 void ensureCapacity(int minCapacity)
          Ensures that the receiver can hold at least the specified number of elements without needing to allocate new internal memory.
 int size()
          Returns the number of contained elements.
 int[] toArray()
          Returns a copied array of bytes containing all elements; the returned array has length = this.size().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayIntList

public ArrayIntList()
Constructs an empty list.


ArrayIntList

public ArrayIntList(int initialCapacity)
Constructs an empty list with the specified initial capacity.

Parameters:
initialCapacity - the number of elements the receiver can hold without auto-expanding itself by allocating new internal memory.
Method Detail

add

public void add(int elem)
Appends the specified element to the end of this list.

Parameters:
elem - element to be appended to this list.

add

public void add(int[] elems,
                int offset,
                int length)
Appends the elements in the range [offset..offset+length) to the end of this list.

Parameters:
elems - the elements to be appended
offset - the offset of the first element to add (inclusive)
length - the number of elements to add
Throws:
IndexOutOfBoundsException - if indexes are out of range.

asArray

public int[] asArray()
Returns the elements currently stored, including invalid elements between size and capacity, if any.

WARNING: For efficiency reasons and to keep memory usage low, the array is SHARED, not copied . So if subsequently you modify the returned array directly via the [] operator, be sure you know what you're doing.

Returns:
the elements currently stored.

clear

public void clear()
Removes all elements but keeps the current capacity; Afterwards size() will yield zero.


ensureCapacity

public void ensureCapacity(int minCapacity)
Ensures that the receiver can hold at least the specified number of elements without needing to allocate new internal memory. If necessary, allocates new internal memory and increases the capacity of the receiver.

Parameters:
minCapacity - the desired minimum capacity.

size

public int size()
Returns the number of contained elements.

Returns:
the number of elements contained in the receiver.

toArray

public int[] toArray()
Returns a copied array of bytes containing all elements; the returned array has length = this.size().


Nux 1.6