FileDocCategorySizeDatePackage
LongArray.javaAPI DocAndroid 5.1 API4591Thu Mar 12 22:22:10 GMT 2015android.util

LongArray

public class LongArray extends Object implements Cloneable
Implements a growing array of long primitives.
hide

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


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

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

        add(mSize, value);
    
public voidadd(int index, long 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.LongArray 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.LongArrayclone()

        LongArray clone = null;
        try {
            clone = (LongArray) super.clone();
            clone.mValues = mValues.clone();
        } catch (CloneNotSupportedException cnse) {
            /* ignore */
        }
        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 long[] newValues = ArrayUtils.newUnpaddedLongArray(newCapacity);
            System.arraycopy(mValues, 0, newValues, 0, currentSize);
            mValues = newValues;
        }
    
public longget(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(long 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;