FileDocCategorySizeDatePackage
IntArray.javaAPI DocAndroid 5.1 API4482Thu Mar 12 22:22:10 GMT 2015android.util

IntArray

public class IntArray extends Object implements Cloneable
Implements a growing array of int primitives.
hide

Fields Summary
private static final int
MIN_CAPACITY_INCREMENT
private int[]
mValues
private int
mSize
Constructors Summary
public IntArray()
Creates an empty IntArray with the default initial capacity.


                  
      
        this(10);
    
public IntArray(int initialCapacity)
Creates an empty IntArray with the specified initial capacity.

        if (initialCapacity == 0) {
            mValues = EmptyArray.INT;
        } else {
            mValues = ArrayUtils.newUnpaddedIntArray(initialCapacity);
        }
        mSize = 0;
    
Methods Summary
public voidadd(int value)
Appends the specified value to the end of this array.

        add(mSize, value);
    
public voidadd(int index, int value)
Inserts a value at the specified position in this array.

throws
IndexOutOfBoundsException when index < 0 || index > size()

        if (index < 0 || index > mSize) {
            throw new IndexOutOfBoundsException();
        }

        ensureCapacity(1);

        if (mSize - index != 0) {
            System.arraycopy(mValues, index, mValues, index + 1, mSize - index);
        }

        mValues[index] = value;
        mSize++;
    
public voidaddAll(android.util.IntArray values)
Adds the values in the specified array to this array.

        final int count = values.mSize;
        ensureCapacity(count);

        System.arraycopy(values.mValues, 0, mValues, mSize, count);
        mSize += count;
    
public voidclear()
Removes all values from this array.

        mSize = 0;
    
public android.util.IntArrayclone()

        final IntArray clone = (IntArray) super.clone();
        clone.mValues = mValues.clone();
        return clone;
    
private voidensureCapacity(int count)
Ensures capacity to append at least count values.

        final int currentSize = mSize;
        final int minCapacity = currentSize + count;
        if (minCapacity >= mValues.length) {
            final int targetCap = currentSize + (currentSize < (MIN_CAPACITY_INCREMENT / 2) ?
                    MIN_CAPACITY_INCREMENT : currentSize >> 1);
            final int newCapacity = targetCap > minCapacity ? targetCap : minCapacity;
            final int[] newValues = ArrayUtils.newUnpaddedIntArray(newCapacity);
            System.arraycopy(mValues, 0, newValues, 0, currentSize);
            mValues = newValues;
        }
    
public intget(int index)
Returns the value at the specified position in this array.

        if (index >= mSize) {
            throw new ArrayIndexOutOfBoundsException(mSize, index);
        }
        return mValues[index];
    
public intindexOf(int value)
Returns the index of the first occurrence of the specified value in this array, or -1 if this array does not contain the value.

        final int n = mSize;
        for (int i = 0; i < n; i++) {
            if (mValues[i] == value) {
                return i;
            }
        }
        return -1;
    
public voidremove(int index)
Removes the value at the specified index from this array.

        if (index >= mSize) {
            throw new ArrayIndexOutOfBoundsException(mSize, index);
        }
        System.arraycopy(mValues, index + 1, mValues, index, mSize - index - 1);
        mSize--;
    
public intsize()
Returns the number of values in this array.

        return mSize;