ewe.util
Class IntArray

java.lang.Object
  extended byewe.util.IntArray
All Implemented Interfaces:
Copyable, Encodable

public class IntArray
extends Object
implements Copyable, Encodable

This is a utility for storing an expandable array of integers. Similar to a Vector but for int values instead.


Field Summary
 int[] data
          This is the array of integers itself.
 int growSize
          This specifies the number of values to increase by when expansion is needed.
 int length
          This specifies the number of valid values in the array.
 
Constructor Summary
IntArray()
          Creates an IntArray with an initial size of 100 and a grow size of 100.
IntArray(int initialSize, int growSize)
          Creates an IntArray with the specified initial size and grow size.
 
Method Summary
 void add(int value)
          Append a value to the end of the array.
 void append(int value)
           
 void append(int[] values, int offset, int length)
           
 int[] appendTo(int[] dest)
          Append all values in this IntArray to the specified destination array.
 int[] appendTo(int[] dest, boolean reverse)
          Append all values in this IntArray to the specified destination array with the option of reversing the order of integers in this IntArray before appending.
 void clear()
          Clears the IntArray completely.
 void copyInto(int[] dest, int offset)
          Copy all values into the destination array at the specified offset.
 Object getCopy()
          Return a copy of this object.
 int indexOf(int value)
          Find the index of the specified value.
 void insert(int[] values, int offset, int length, int where)
           
 void insert(int value, int index)
          Insert a value at the specified index.
 boolean makeSpace(int where, int num)
          This adds space to the IntArray at the specified index, increasing the length value by num.
 void remove(int value)
          Remove the value if it is in the array.
 void removeAtIndex(int index)
          Remove the value at the specified index.
 int[] toIntArray()
          Return a copy of the array of integers whose length exactly holds all added integers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, toString
 

Field Detail

data

public int[] data
This is the array of integers itself. This can be changed while the array is being used.


length

public int length
This specifies the number of valid values in the array.


growSize

public int growSize
This specifies the number of values to increase by when expansion is needed. If it is zero or negative then everytime an increase is needed the size of the data will be doubled (this is the default).

Constructor Detail

IntArray

public IntArray()
Creates an IntArray with an initial size of 100 and a grow size of 100.


IntArray

public IntArray(int initialSize,
                int growSize)
Creates an IntArray with the specified initial size and grow size.

Method Detail

getCopy

public Object getCopy()
Description copied from interface: Copyable
Return a copy of this object.

Specified by:
getCopy in interface Copyable

clear

public void clear()
Clears the IntArray completely.


add

public void add(int value)
Append a value to the end of the array.


append

public void append(int value)

makeSpace

public boolean makeSpace(int where,
                         int num)
This adds space to the IntArray at the specified index, increasing the length value by num. After this is done you can safely write into the data starting at index "where" for a length of num.


insert

public void insert(int[] values,
                   int offset,
                   int length,
                   int where)

append

public void append(int[] values,
                   int offset,
                   int length)

insert

public void insert(int value,
                   int index)
Insert a value at the specified index.


indexOf

public int indexOf(int value)
Find the index of the specified value. Returns -1 if it could not be found.


remove

public void remove(int value)
Remove the value if it is in the array.


removeAtIndex

public void removeAtIndex(int index)
Remove the value at the specified index.


toIntArray

public int[] toIntArray()
Return a copy of the array of integers whose length exactly holds all added integers.


copyInto

public void copyInto(int[] dest,
                     int offset)
Copy all values into the destination array at the specified offset.


appendTo

public int[] appendTo(int[] dest)
Append all values in this IntArray to the specified destination array. If the destination array is null it is treated as an array of zero length. A new int array is returned which holds the new array of integers.


appendTo

public int[] appendTo(int[] dest,
                      boolean reverse)
Append all values in this IntArray to the specified destination array with the option of reversing the order of integers in this IntArray before appending. If the destination array is null it is treated as an array of zero length. A new int array is returned which holds the new array of integers.