/** * Perform a {@link #add(Object)} of all values in <var>array</var> * @param array The array whose contents are to be retrieved. */ public void addAll(ArraySet<? extends E> array) { final int N = array.mSize; ensureCapacity(mSize + N); if (mSize == 0) { if (N > 0) { System.arraycopy(array.mHashes, 0, mHashes, 0, N); System.arraycopy(array.mArray, 0, mArray, 0, N); mSize = N; } } else { for (int i=0; i<N; i++) { add(array.valueAt(i)); } } }
/** {@hide} */ public ArraySet(Collection<E> set) { this(); if (set != null) { addAll(set); } }
if (value == null) { hash = 0; index = indexOfNull(); } else { hash = value.hashCode(); index = indexOf(value, hash); allocArrays(n); freeArrays(ohashes, oarray, mSize);
/** * Removes the specified object from this set. * * @param object the object to remove. * @return {@code true} if this set was modified, {@code false} otherwise. */ @Override public boolean remove(Object object) { final int index = indexOf(object); if (index >= 0) { removeAt(index); return true; } return false; }
/** * Returns the index of a value in the set. * * @param key The value to search for. * @return Returns the index of the value if it exists, else a negative integer. */ public int indexOf(Object key) { return key == null ? indexOfNull() : indexOf(key, key.hashCode()); }
/** * Perform an {@link #add(Object)} of all values in <var>collection</var> * @param collection The collection whose contents are to be retrieved. */ @Override public boolean addAll(Collection<? extends E> collection) { ensureCapacity(mSize + collection.size()); boolean added = false; for (E value : collection) { added |= add(value); } return added; }
/** * Ensure the array map can hold at least <var>minimumCapacity</var> * items. */ public void ensureCapacity(int minimumCapacity) { if (mHashes.length < minimumCapacity) { final int[] ohashes = mHashes; final Object[] oarray = mArray; allocArrays(minimumCapacity); if (mSize > 0) { System.arraycopy(ohashes, 0, mHashes, 0, mSize); System.arraycopy(oarray, 0, mArray, 0, mSize); } freeArrays(ohashes, oarray, mSize); } }
/** * Check whether a value exists in the set. * * @param key The value to search for. * @return Returns true if the value exists, else false. */ @Override public boolean contains(Object key) { return indexOf(key) >= 0; }
/** * Return an {@link java.util.Iterator} over all values in the set. * * <p><b>Note:</b> this is a fairly inefficient way to access the array contents, it * requires generating a number of temporary objects and allocates additional state * information associated with the container that will remain for the life of the container.</p> */ @Override public Iterator<E> iterator() { return getCollection().getKeySet().iterator(); }
/** * Make the array map empty. All storage is released. */ @Override public void clear() { if (mSize != 0) { freeArrays(mHashes, mArray, mSize); mHashes = ContainerHelpers.EMPTY_INTS; mArray = ContainerHelpers.EMPTY_OBJECTS; mSize = 0; } }
@Override protected void colClear() { clear(); } };
/** * Create a new ArraySet with a given initial capacity. */ public ArraySet(int capacity) { if (capacity == 0) { mHashes = ContainerHelpers.EMPTY_INTS; mArray = ContainerHelpers.EMPTY_OBJECTS; } else { allocArrays(capacity); } mSize = 0; }
@Override protected void colPut(E key, E value) { add(key); }
/** * Determine if the array set contains all of the values in the given collection. * @param collection The collection whose contents are to be checked against. * @return Returns true if this array set contains a value for every entry * in <var>collection</var>, else returns false. */ @Override public boolean containsAll(Collection<?> collection) { Iterator<?> it = collection.iterator(); while (it.hasNext()) { if (!contains(it.next())) { return false; } } return true; }
@Override public Object call(Object who, Method method, Object... args) throws Throwable { int uid = (int) args[0]; int callingUid = Binder.getCallingUid(); if (uid == VirtualCore.get().myUid()) { uid = getBaseVUid(); } String[] callingPkgs = VPackageManager.get().getPackagesForUid(callingUid); String[] targetPkgs = VPackageManager.get().getPackagesForUid(uid); String[] selfPkgs = VPackageManager.get().getPackagesForUid(Process.myUid()); Set<String> pkgList = new ArraySet<>(2); if (callingPkgs != null && callingPkgs.length > 0) { pkgList.addAll(Arrays.asList(callingPkgs)); } if (targetPkgs != null && targetPkgs.length > 0) { pkgList.addAll(Arrays.asList(targetPkgs)); } if (selfPkgs != null && selfPkgs.length > 0) { pkgList.addAll(Arrays.asList(selfPkgs)); } return pkgList.toArray(new String[pkgList.size()]); }
freeArrays(mHashes, mArray, mSize); mHashes = ContainerHelpers.EMPTY_INTS; mArray = ContainerHelpers.EMPTY_OBJECTS; allocArrays(n);
/** * Returns the index of a value in the set. * * @param key The value to search for. * @return Returns the index of the value if it exists, else a negative integer. */ public int indexOf(Object key) { return key == null ? indexOfNull() : indexOf(key, key.hashCode()); }
/** * Perform an {@link #add(Object)} of all values in <var>collection</var> * @param collection The collection whose contents are to be retrieved. */ @Override public boolean addAll(Collection<? extends E> collection) { ensureCapacity(mSize + collection.size()); boolean added = false; for (E value : collection) { added |= add(value); } return added; }
/** * Removes the specified object from this set. * * @param object the object to remove. * @return {@code true} if this set was modified, {@code false} otherwise. */ @Override public boolean remove(Object object) { final int index = indexOf(object); if (index >= 0) { removeAt(index); return true; } return false; }
@Override protected int colIndexOfKey(Object key) { return indexOf(key); }