MiscUtils { public static <T> void exclusiveAdd(final List<T> list, @Nullable final List<T> elementsToAdd) { if (elementsToAdd == null || elementsToAdd.isEmpty()) { return; } for (final T elementToAdd : elementsToAdd) { final int indexOf = list.indexOf(elementToAdd); if (indexOf == -1) { list.add(elementToAdd); } else { list.set(indexOf, elementToAdd); } } }  static boolean booleanEquals(@Nullable final Boolean lhs, @Nullable final Boolean rhs); static void closeKeyboard(final Activity activity); static void exclusiveAdd(final List<T> list, @Nullable final List<T> elementsToAdd); static Activity getActivity(final Context context); @ColorInt static int getAttrColor(final Context context, @AttrRes final int colorResId); @ColorInt static int getDrawableColor(final Context context, @Nullable final Drawable drawable); @ColorInt static int getDrawableColor(final View view, @Nullable final Drawable drawable); static CharSequence getElapsedTime(final Resources res, long seconds); @Nullable static String[] getGroupLogos(@Nullable final String logo); static LayerDrawable getStatusBarScrim(final Context context,
            @Nullable final Drawable statusBarBackground); @Nullable static String[] getUserAvatars(@Nullable final String avatar); static int integerCompare(final int lhs, final int rhs); static boolean integerEquals(@Nullable final Integer lhs, @Nullable final Integer rhs); static boolean isLowRamDevice(); static boolean isValidArtwork(final String url); static void openKeyboard(final Context context, final View view); static void openUrl(final Activity activity, final String url); static void openUrl(final Context context, final String url); @Nullable static Activity optActivity(@Nullable final Context context); @Nullable static ArrayList<T> toArrayList(@Nullable final Collection<T> collection);  }
@Test public void testExclusiveAdd() throws Exception { final ArrayList<Integer> list = new ArrayList<>(); list.add(1); list.add(2); list.add(3); MiscUtils.exclusiveAdd(list, Arrays.asList(1, 2, 3)); assertTrue(list.size() == 3); MiscUtils.exclusiveAdd(list, Arrays.asList(1, 2, 3, 6)); assertTrue(list.size() == 4); MiscUtils.exclusiveAdd(list, Arrays.asList(10, 20, 30, 1)); assertTrue(list.size() == 7); MiscUtils.exclusiveAdd(list, Arrays.asList(30, 3, 2, 1, 6)); assertTrue(list.size() == 7); MiscUtils.exclusiveAdd(list, null); assertTrue(list.size() == 7); MiscUtils.exclusiveAdd(list, new ArrayList<Integer>()); assertTrue(list.size() == 7); MiscUtils.exclusiveAdd(list, new LinkedList<Integer>()); assertTrue(list.size() == 7); }