/** * Given an index in the range <code>0...size()-1</code>, returns * the key from the <code>index</code>th key-value mapping that this * SparseArray stores. */ public int keyAt(int index) { if (mGarbage) { gc(); } return mKeys[index]; }
/** * Given an index in the range <code>0...size()-1</code>, sets a new * value for the <code>index</code>th key-value mapping that this * SparseArray stores. */ public void setValueAt(int index, E value) { if (mGarbage) { gc(); } mValues[index] = value; }
/** * Returns the number of key-value mappings that this SparseArray * currently stores. */ public int size() { if (mGarbage) { gc(); } return mSize; }
/** * Given an index in the range <code>0...size()-1</code>, sets a new * value for the <code>index</code>th key-value mapping that this * SparseArray stores. */ public void setValueAt(int index, E value) { if (mGarbage) { gc(); } mValues[index] = value; }
/** * Given an index in the range <code>0...size()-1</code>, returns * the key from the <code>index</code>th key-value mapping that this * SparseArray stores. */ public int keyAt(int index) { if (mGarbage) { gc(); } return mKeys[index]; }
/** * Given an index in the range <code>0...size()-1</code>, returns * the value from the <code>index</code>th key-value mapping that this * SparseArray stores. */ public E valueAt(int index) { if (mGarbage) { gc(); } return (E) mValues[index]; }
/** * Returns the number of key-value mappings that this SparseArray * currently stores. */ public int size() { if (mGarbage) { gc(); } return mSize; }
/** * Given an index in the range <code>0...size()-1</code>, sets a new * value for the <code>index</code>th key-value mapping that this * SparseArray stores. */ public void setValueAt(int index, E value) { if (mGarbage) { gc(); } mValues[index] = value; }
/** * Given an index in the range <code>0...size()-1</code>, returns * the value from the <code>index</code>th key-value mapping that this * SparseArray stores. */ public E valueAt(int index) { if (mGarbage) { gc(); } return (E) mValues[index]; }
/** * Given an index in the range <code>0...size()-1</code>, returns * the key from the <code>index</code>th key-value mapping that this * SparseArray stores. */ public int keyAt(int index) { if (mGarbage) { gc(); } return mKeys[index]; }
/** * Returns the number of key-value mappings that this SparseArray * currently stores. */ public int size() { if (mGarbage) { gc(); } return mSize; }
/** * Given an index in the range <code>0...size()-1</code>, returns * the value from the <code>index</code>th key-value mapping that this * SparseArray stores. */ public E valueAt(int index) { if (mGarbage) { gc(); } return (E) mValues[index]; }
/** * Returns an index for which {@link #valueAt} would return the * specified key, or a negative number if no keys map to the * specified value. * Beware that this is a linear search, unlike lookups by key, * and that multiple keys can map to the same value and this will * find only one of them. */ public int indexOfValue(E value) { if (mGarbage) { gc(); } for (int i = 0; i < mSize; i++) if (mValues[i] == value) return i; return -1; }
/** * Returns an index for which {@link #valueAt} would return the * specified key, or a negative number if no keys map to the * specified value. * Beware that this is a linear search, unlike lookups by key, * and that multiple keys can map to the same value and this will * find only one of them. */ public int indexOfValue(E value) { if (mGarbage) { gc(); } for (int i = 0; i < mSize; i++) if (mValues[i] == value) return i; return -1; }
/** * Returns an index for which {@link #valueAt} would return the * specified key, or a negative number if no keys map to the * specified value. * Beware that this is a linear search, unlike lookups by key, * and that multiple keys can map to the same value and this will * find only one of them. */ public int indexOfValue(E value) { if (mGarbage) { gc(); } for (int i = 0; i < mSize; i++) if (mValues[i] == value) return i; return -1; }
/** * Increases the size of the underlying storage if needed, to ensure that it can * hold the specified number of items without having to allocate additional memory * @param capacity the number of items */ public void ensureCapacity(int capacity) { if (mGarbage && mSize >= mKeys.length) { gc(); } if (mKeys.length < capacity) { int[] nkeys = new int[capacity]; Object[] nvalues = new Object[capacity]; System.arraycopy(mKeys, 0, nkeys, 0, mKeys.length); System.arraycopy(mValues, 0, nvalues, 0, mValues.length); mKeys = nkeys; mValues = nvalues; } }
/** * Increases the size of the underlying storage if needed, to ensure that it can * hold the specified number of items without having to allocate additional memory * @param capacity the number of items */ public void ensureCapacity(int capacity) { if (mGarbage && mSize >= mKeys.length) { gc(); } if (mKeys.length < capacity) { int[] nkeys = new int[capacity]; Object[] nvalues = new Object[capacity]; System.arraycopy(mKeys, 0, nkeys, 0, mKeys.length); System.arraycopy(mValues, 0, nvalues, 0, mValues.length); mKeys = nkeys; mValues = nvalues; } }
/** * Returns the index for which {@link #keyAt} would return the * specified key, or a negative number if the specified * key is not mapped. */ public int indexOfKey(int key) { if (mGarbage) { gc(); } return binarySearch(mKeys, 0, mSize, key); }
/** * Returns the index for which {@link #keyAt} would return the * specified key, or a negative number if the specified * key is not mapped. */ public int indexOfKey(int key) { if (mGarbage) { gc(); } return binarySearch(mKeys, 0, mSize, key); }
/** * Returns the index for which {@link #keyAt} would return the * specified key, or a negative number if the specified * key is not mapped. */ public int indexOfKey(int key) { if (mGarbage) { gc(); } return binarySearch(mKeys, 0, mSize, key); }