Java 类android.util.ArraySet 实例源码

项目:android_packages_apps_tv    文件:SetupUtils.java   
private SetupUtils(TvApplication tvApplication) {
    mTvApplication = tvApplication;
    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(tvApplication);
    mSetUpInputs = new ArraySet<>();
    mSetUpInputs.addAll(mSharedPreferences.getStringSet(PREF_KEY_SET_UP_INPUTS,
            Collections.emptySet()));
    mKnownInputs = new ArraySet<>();
    mKnownInputs.addAll(mSharedPreferences.getStringSet(PREF_KEY_KNOWN_INPUTS,
            Collections.emptySet()));
    mRecognizedInputs = new ArraySet<>();
    mRecognizedInputs.addAll(mSharedPreferences.getStringSet(PREF_KEY_RECOGNIZED_INPUTS,
            mKnownInputs));
    mIsFirstTune = mSharedPreferences.getBoolean(PREF_KEY_IS_FIRST_TUNE, true);
    mTunerInputId = TvContract.buildInputId(new ComponentName(tvApplication,
            TunerTvInputService.class));
}
项目:UseCases    文件:GenericRecyclerViewAdapter.java   
@SuppressWarnings(UNUSED)
public void appendWithoutDuplicateIds(List<ItemInfo> itemInfoList) {
    validateList(itemInfoList);
    if (android.os.Build.VERSION.SDK_INT >= M) {
        ArraySet<ItemInfo> arraySet = new ArraySet<>();
        arraySet.addAll(itemInfoList);
        itemInfoList.clear();
        itemInfoList.addAll(arraySet);
    } else {
        Set<ItemInfo> set = new HashSet<>(itemInfoList);
        itemInfoList.clear();
        itemInfoList.addAll(set);
    }
    mDataList.addAll(itemInfoList);
    ArrayList<Long> finalList = new ArrayList<>();
    ItemInfo item;
    for (int i = 0; i < mDataList.size(); i++) {
        item = mDataList.get(i);
        if (finalList.contains(item.getId())) {
            mDataList.remove(item);
        } else {
            finalList.add(item.getId());
        }
    }
    notifyDataSetChanged();
}
项目:OpenYOLO-Android    文件:CollectionConverter.java   
@NonNull
private static <T> Set<T> createSet(int size) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return new ArraySet<>(size);
    } else {
        return new HashSet<>();
    }
}
项目:zonebeacon    文件:ZoneBeaconRobolectricSuite.java   
@SuppressLint("NewApi")
@After
public void resetWindowManager() throws Exception {
    // https://github.com/robolectric/robolectric/pull/1741
    final Class<?> btclass = Class.forName("com.android.internal.os.BackgroundThread");
    Object backgroundThreadSingleton = ReflectionHelpers.getStaticField(btclass,"sInstance");
    if (backgroundThreadSingleton!=null) {
        btclass.getMethod("quit").invoke(backgroundThreadSingleton);
        ReflectionHelpers.setStaticField(btclass, "sInstance", null);
        ReflectionHelpers.setStaticField(btclass, "sHandler", null);
    }

    // https://github.com/robolectric/robolectric/issues/2068
    Class clazz = ReflectionHelpers.loadClass(getClass().getClassLoader(), "android.view.WindowManagerGlobal");
    Object instance = ReflectionHelpers.callStaticMethod(clazz, "getInstance");

    // We essentially duplicate what's in {@link WindowManagerGlobal#closeAll} with what's below.
    // The closeAll method has a bit of a bug where it's iterating through the "roots" but
    // bases the number of objects to iterate through by the number of "views." This can result in
    // an {@link java.lang.IndexOutOfBoundsException} being thrown.
    Object lock = ReflectionHelpers.getField(instance, "mLock");

    ArrayList<Object> roots = ReflectionHelpers.getField(instance, "mRoots");
    //noinspection SynchronizationOnLocalVariableOrMethodParameter
    synchronized (lock) {
        for (int i = 0; i < roots.size(); i++) {
            ReflectionHelpers.callInstanceMethod(instance, "removeViewLocked",
                    ReflectionHelpers.ClassParameter.from(int.class, i),
                    ReflectionHelpers.ClassParameter.from(boolean.class, false));
        }
    }

    // Views will still be held by this array. We need to clear it out to ensure
    // everything is released.
    ArraySet<View> dyingViews = ReflectionHelpers.getField(instance, "mDyingViews");
    dyingViews.clear();
}
项目:android_packages_apps_tv    文件:MultiLongSparseArray.java   
private Set<T> getEmptySet() {
    if (mEmptyIndex < 0) {
        return new ArraySet<>();
    }
    Set<T> emptySet = mEmptySets[mEmptyIndex];
    mEmptySets[mEmptyIndex--] = null;
    return emptySet;
}
项目:DownloadManager    文件:ArrayUtils.java   
public static <T> ArraySet<T> add(ArraySet<T> cur, T val) {
    if (cur == null) {
        cur = new ArraySet<>();
    }
    cur.add(val);
    return cur;
}
项目:DownloadManager    文件:ArrayUtils.java   
public static <T> ArraySet<T> remove(ArraySet<T> cur, T val) {
    if (cur == null) {
        return null;
    }
    cur.remove(val);
    if (cur.isEmpty()) {
        return null;
    } else {
        return cur;
    }
}
项目:j2objc    文件:Sets.java   
/**
 * Creates a {@code ArraySet} instance containing the given elements.
 */
public static <E> ArraySet<E> newArraySet(E... elements) {
    int capacity = elements.length * 4 / 3 + 1;
    ArraySet<E> set = new ArraySet<E>(capacity);
    Collections.addAll(set, elements);
    return set;
}
项目:android-AutofillFramework    文件:SharedPrefsAutofillRepository.java   
private Set<String> getAllAutofillDataStringSet(Context context) {
    return context.getApplicationContext()
            .getSharedPreferences(SHARED_PREF_KEY, Context.MODE_PRIVATE)
            .getStringSet(CLIENT_FORM_DATA_KEY, new ArraySet<String>());
}
项目:DownloadManager    文件:ArrayUtils.java   
public static <T> boolean contains(ArraySet<T> cur, T val) {
    return (cur != null) ? cur.contains(val) : false;
}
项目:j2objc    文件:Sets.java   
/**
 * Creates a {@code ArraySet} instance.
 */
public static <E> ArraySet<E> newArraySet() {
    return new ArraySet<E>();
}