com.triactive.jdo.util
Class IntArrayList

java.lang.Object
  extended bycom.triactive.jdo.util.IntArrayList
All Implemented Interfaces:
java.lang.Cloneable

public class IntArrayList
extends java.lang.Object
implements java.lang.Cloneable

A variation on the standard ArrayList class that efficiently handles arrays of integers. Using this class rather than ArrayList avoids the need to "box" each element in an instance of java.lang.Integer. It is useful where performance is important.

Author:
Mike Martin

Constructor Summary
IntArrayList()
          Constructs an empty list with an initial capacity of ten.
IntArrayList(int initialCapacity)
          Constructs an empty list with the specified initial capacity.
IntArrayList(int[] initialContents)
          Constructs a list containing the elements of the specified array.
 
Method Summary
 void add(int element)
          Appends the specified element to the end of this list.
 void add(int index, int element)
          Inserts the specified element at the specified position in this list.
 void addAll(int[] ai)
          Appends all of the elements in the specified array to the end of this list.
 void addAll(int index, int[] ai)
          Inserts all of the elements in the specified array into this list, starting at the specified position.
 void clear()
          Removes all of the elements from this list.
 java.lang.Object clone()
          Returns a copy of this IntArrayList instance.
 boolean contains(int elem)
          Returns true if this list contains the specified element.
 boolean containsAll(int[] ai)
          Returns true if this list contains all of the elements in the specified list.
 void ensureCapacity(int minCapacity)
          Increases the capacity of this IntArrayList instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.
 boolean equals(java.lang.Object o)
          Compares the specified object with this list for equality.
 int get(int index)
          Returns the element at the specified position in this list.
 int hashCode()
          Returns the hash code value for this list.
 int indexOf(int elem)
          Searches for the first occurence of the given argument.
 boolean isEmpty()
          Tests if this list has no elements.
 int lastIndexOf(int elem)
          Returns the index of the last occurrence of the specified integer in this list.
 int remove(int index)
          Removes the element at the specified position in this list.
 boolean removeAll(int[] ai)
          Removes from this list all of its elements that are contained in the specified array.
 boolean retainAll(int[] ai)
          Retains only the elements in this list that are contained in the specified array.
 int set(int index, int element)
          Replaces the element at the specified position in this list with the specified element.
 int size()
          Returns the number of elements in this list.
 int[] toArray()
          Returns an array containing all of the elements in this list.
 java.lang.String toString()
          Returns a string representation of this list.
 void trimToSize()
          Trims the capacity of this IntArrayList instance to be the list's current size.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IntArrayList

public IntArrayList()
Constructs an empty list with an initial capacity of ten.


IntArrayList

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

Parameters:
initialCapacity - The initial capacity of the list.
Throws:
java.lang.IllegalArgumentException - If the specified initial capacity is negative.

IntArrayList

public IntArrayList(int[] initialContents)
Constructs a list containing the elements of the specified array. The IntArrayList instance has an initial capacity of 110% the size of the specified collection.

Parameters:
initialContents - The array whose elements are to be placed into this list.
Method Detail

trimToSize

public void trimToSize()
Trims the capacity of this IntArrayList instance to be the list's current size. An application can use this operation to minimize the storage of an IntArrayList instance.


ensureCapacity

public void ensureCapacity(int minCapacity)
Increases the capacity of this IntArrayList instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.

Parameters:
minCapacity - The desired minimum capacity.

size

public int size()
Returns the number of elements in this list.

Returns:
The number of elements in this list.

isEmpty

public boolean isEmpty()
Tests if this list has no elements.

Returns:
true if this list has no elements; false otherwise.

contains

public boolean contains(int elem)
Returns true if this list contains the specified element.

Parameters:
elem - element whose presence in this List is to be tested.
Returns:
true if the specified element is present; false otherwise.

indexOf

public int indexOf(int elem)
Searches for the first occurence of the given argument.

Parameters:
elem - An integer to search for.
Returns:
The index of the first occurrence of the argument in this list; returns -1 if the value is not found.

lastIndexOf

public int lastIndexOf(int elem)
Returns the index of the last occurrence of the specified integer in this list.

Parameters:
elem - The desired element.
Returns:
The index of the last occurrence of the specified integer in this list; returns -1 if the value is not found.

clone

public java.lang.Object clone()
Returns a copy of this IntArrayList instance.

Returns:
A clone of this ArrayList instance.

toArray

public int[] toArray()
Returns an array containing all of the elements in this list.

Returns:
An array containing all of the elements in this list.

get

public int get(int index)
Returns the element at the specified position in this list.

Parameters:
index - Index of element to return.
Returns:
The element at the specified position in this list.
Throws:
java.lang.IndexOutOfBoundsException - If index is out of range (index < 0 || index >= size()).

set

public int set(int index,
               int element)
Replaces the element at the specified position in this list with the specified element.

Parameters:
index - Index of element to replace.
element - Element to be stored at the specified position.
Returns:
The element previously at the specified position.
Throws:
java.lang.IndexOutOfBoundsException - If index is out of range (index < 0 || index >= size()).

add

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

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

add

public void add(int index,
                int element)
Inserts the specified element at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

Parameters:
index - Index at which the specified element is to be inserted.
element - Element to be inserted.
Throws:
java.lang.IndexOutOfBoundsException - If index is out of range (index < 0 || index > size()).

remove

public int remove(int index)
Removes the element at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices).

Parameters:
index - The index of the element to removed.
Returns:
The element that was removed from the list.
Throws:
java.lang.IndexOutOfBoundsException - If index is out of range (index < 0 || index >= size()).

clear

public void clear()
Removes all of the elements from this list. The list will be empty after this call returns.


addAll

public void addAll(int[] ai)
Appends all of the elements in the specified array to the end of this list.

Parameters:
ai - The elements to be added to this list.

addAll

public void addAll(int index,
                   int[] ai)
Inserts all of the elements in the specified array into this list, starting at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in the list in the order that they exist in the array argument.

Parameters:
index - Index at which to insert first element from the specified array.
ai - Elements to be inserted into this list.
Throws:
java.lang.IndexOutOfBoundsException - If index is out of range (index < 0 || index > size()).

containsAll

public boolean containsAll(int[] ai)
Returns true if this list contains all of the elements in the specified list.

This implementation iterates over the specified array, checking each element in turn to see if it's contained in this list. If all elements are so contained true is returned, otherwise false.

Parameters:
ai - Array to be checked for containment in this list.
Returns:
true if this list contains all of the elements in the specified array.
See Also:
contains(int)

removeAll

public boolean removeAll(int[] ai)
Removes from this list all of its elements that are contained in the specified array.

This implementation iterates over this list, checking each element in turn to see if it's contained in the specified array. If it's so contained, it's removed from this list.

Parameters:
ai - Elements to be removed from this list.
Returns:
true if this list changed as a result of the call.
See Also:
remove(int), contains(int)

retainAll

public boolean retainAll(int[] ai)
Retains only the elements in this list that are contained in the specified array. In other words, removes from this list all of its elements that are not contained in the specified array.

This implementation iterates over this list, checking each element in turn to see if it's contained in the specified array. If it's not so contained, it's removed from this list.

Parameters:
ai - Elements to be retained in this list.
Returns:
true if this list changed as a result of the call.
See Also:
remove(int), contains(int)

equals

public boolean equals(java.lang.Object o)
Compares the specified object with this list for equality. Returns true if and only if the specified object is also an IntArrayList, both lists have the same size, and all corresponding pairs of elements in the two lists are equal.

Parameters:
o - the object to be compared for equality with this list.
Returns:
true if the specified object is equal to this list.

hashCode

public int hashCode()
Returns the hash code value for this list.

Returns:
The hash code value for this list.

toString

public java.lang.String toString()
Returns a string representation of this list. The string representation consists of a list of the elements, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (comma and space). Elements are converted to strings as by String.valueOf(int).

Returns:
A string representation of this collection.


Copyright © 2001-2007 The TJDO Project All Rights Reserved.