/** * Gets the Object mapped from the specified key, or <code>null</code> * if no such mapping has been made. */ public E get(int key) { return get(key, null); }
/** * 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); }
/** * Alias for {@link #delete(int)}. */ public void remove(int key) { delete(key); }
SparseArray<Set<String>> commandOutputsConsumed = new SparseArray<>(); commandOutputsConsumed.put(i, new HashSet<>()); commandOutputsConsumed.get(inputCommandIndex).add(input); continue; for (int i = 0; i < commandSummaries.size(); ++i) { BuildStepInfo current = commandSummaries.get(i); Set<String> outputsConsumed = commandOutputsConsumed.get(i); for (String output : current.getOutputs()) { if (!outputsConsumed.contains(output) || !current.inputsAreSourceFiles()) {
/** * Puts a key/value pair into the array, optimizing for the case where * the key is greater than all existing keys in the array. */ public void append(int key, E value) { if (mSize != 0 && key <= mKeys[mSize - 1]) { put(key, value); return; } if (mGarbage && mSize >= mKeys.length) { gc(); } int pos = mSize; if (pos >= mKeys.length) { int n = ArrayUtils.idealIntArraySize(pos + 1); int[] nkeys = new int[n]; Object[] nvalues = new Object[n]; // Log.e("SparseArray", "grow " + mKeys.length + " to " + n); System.arraycopy(mKeys, 0, nkeys, 0, mKeys.length); System.arraycopy(mValues, 0, nvalues, 0, mValues.length); mKeys = nkeys; mValues = nvalues; } mKeys[pos] = key; mValues[pos] = value; mSize = pos + 1; }
public FakeAndroidTarget(String sdkLocation, String target) { mSdkLocation = sdkLocation; mApiLevel = getApiLevel(target); if ("unstubbed".equals(target)) { mBootClasspath.add(mSdkLocation + "/out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.jar"); mBootClasspath.add(mSdkLocation + "/out/target/common/obj/JAVA_LIBRARIES/core_intermediates/classes.jar"); // pre-build the path to the platform components mPaths.put(ANDROID_JAR, mSdkLocation + "/prebuilts/sdk/current/" + SdkConstants.FN_FRAMEWORK_LIBRARY); mPaths.put(ANDROID_AIDL, mSdkLocation + "/prebuilts/sdk/renderscript/" + SdkConstants.FN_FRAMEWORK_AIDL); } else { String apiPrebuilts; if ("current".equals(target)) { apiPrebuilts = mSdkLocation + "/prebuilts/sdk/current/"; } else { apiPrebuilts = mSdkLocation + "/prebuilts/sdk/" + Integer.toString(mApiLevel) + "/"; } // pre-build the path to the platform components mBootClasspath.add(apiPrebuilts + SdkConstants.FN_FRAMEWORK_LIBRARY); mPaths.put(ANDROID_JAR, apiPrebuilts + SdkConstants.FN_FRAMEWORK_LIBRARY); mPaths.put(ANDROID_AIDL, apiPrebuilts + SdkConstants.FN_FRAMEWORK_AIDL); } }
public SparseArray<E> getUnmodifiable() { final SparseArray<E> mStorage = this; return new SparseArray<E>() {
/** * Returns the number of key-value mappings that this SparseArray * currently stores. */ public int size() { if (mGarbage) { gc(); } return mSize; }
/** * Gets the Object mapped from the specified key, or the specified Object * if no such mapping has been made. */ @SuppressWarnings("unchecked") public E get(int key, E valueIfKeyNotFound) { int i = binarySearch(mKeys, 0, mSize, key); if (i < 0 || mValues[i] == DELETED) { return valueIfKeyNotFound; } else { return (E) mValues[i]; } }
@Override public int indexOfKey(int key) { return mStorage.indexOfKey(key); }
public FakeAndroidTarget(String sdkLocation, String target) { mSdkLocation = sdkLocation; mApiLevel = getApiLevel(target); if ("unstubbed".equals(target)) { mBootClasspath.add(mSdkLocation + "/out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.jar"); mBootClasspath.add(mSdkLocation + "/out/target/common/obj/JAVA_LIBRARIES/core_intermediates/classes.jar"); // pre-build the path to the platform components mPaths.put(ANDROID_JAR, mSdkLocation + "/prebuilts/sdk/current/" + SdkConstants.FN_FRAMEWORK_LIBRARY); mPaths.put(ANDROID_AIDL, mSdkLocation + "/prebuilts/sdk/renderscript/" + SdkConstants.FN_FRAMEWORK_AIDL); } else { String apiPrebuilts; if ("current".equals(target)) { apiPrebuilts = mSdkLocation + "/prebuilts/sdk/current/"; } else { apiPrebuilts = mSdkLocation + "/prebuilts/sdk/" + Integer.toString(mApiLevel) + "/"; } // pre-build the path to the platform components mBootClasspath.add(apiPrebuilts + SdkConstants.FN_FRAMEWORK_LIBRARY); mPaths.put(ANDROID_JAR, apiPrebuilts + SdkConstants.FN_FRAMEWORK_LIBRARY); mPaths.put(ANDROID_AIDL, apiPrebuilts + SdkConstants.FN_FRAMEWORK_AIDL); } }
/** * 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; }
/** * Removes the mapping from the specified key, if there was any. */ public void delete(int key) { int i = binarySearch(mKeys, 0, mSize, key); if (i >= 0) { if (mValues[i] != DELETED) { mValues[i] = DELETED; mGarbage = true; } } }
@Override public E get(int key) { return mStorage.get(key); }
int i = binarySearch(mKeys, 0, mSize, key); gc(); i = ~binarySearch(mKeys, 0, mSize, key);
/** * 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]; }
@Override public E get(int key, E valueIfKeyNotFound) { return mStorage.get(key, valueIfKeyNotFound); }
/** * 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. */ @SuppressWarnings("unchecked") public E valueAt(int index) { if (mGarbage) { gc(); } return (E) mValues[index]; }
@Override public String getPath(int pathId) { return mPaths.get(pathId); }
/** * 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; }