@Test public void testRemoveAllFor() { long init = 3000000000000000L; long[] sources = new long[10]; for (int i = 0; i < sources.length; i++) { sources[i] = init + i; } for (int i = 0; i < 10; i++) { HashSet<Long> removeSet = new HashSet<Long>(); for (int j = 0; j < i; j++) { removeSet.add(init + RandomUtils.nextInt(i)); } long[] removes = new long[removeSet.size()]; int j = 0; for (Long remove : removeSet) { removes[j++] = remove; } long[] results = ArrayUtil.removeAll(sources, removes); Assert.assertEquals(results.length, sources.length - removes.length); } }
public static long[] removeAll(long[] sourceArray, long[] removeArray) { int sourceLength = sourceArray.length; int removeLength = removeArray.length; if (sourceLength == 0 || removeLength == 0) { return sourceArray; } long[] temp = new long[sourceLength]; int i = 0; if (removeLength > 2) { Set<Long> removeSet = new HashSet<Long>(removeLength); for (long remove : removeArray) { removeSet.add((Long)remove); } for (long source : sourceArray) { if (!removeSet.contains((Long)source)) { temp[i++] = source; } } } else { for (long source : sourceArray) { if (!arrayContains(removeArray, source)) { temp[i++] = source; } } } if (i < temp.length) { return Arrays.copyOf(temp, i); } else { return temp; } }
ArrayUtil { public static long[] removeAll(long[] sourceArray, long[] removeArray) { int sourceLength = sourceArray.length; int removeLength = removeArray.length; if (sourceLength == 0 || removeLength == 0) { return sourceArray; } long[] temp = new long[sourceLength]; int i = 0; if (removeLength > 2) { Set<Long> removeSet = new HashSet<Long>(removeLength); for (long remove : removeArray) { removeSet.add((Long)remove); } for (long source : sourceArray) { if (!removeSet.contains((Long)source)) { temp[i++] = source; } } } else { for (long source : sourceArray) { if (!arrayContains(removeArray, source)) { temp[i++] = source; } } } if (i < temp.length) { return Arrays.copyOf(temp, i); } else { return temp; } } }
ArrayUtil { public static long[] removeAll(long[] sourceArray, long[] removeArray) { int sourceLength = sourceArray.length; int removeLength = removeArray.length; if (sourceLength == 0 || removeLength == 0) { return sourceArray; } long[] temp = new long[sourceLength]; int i = 0; if (removeLength > 2) { Set<Long> removeSet = new HashSet<Long>(removeLength); for (long remove : removeArray) { removeSet.add((Long)remove); } for (long source : sourceArray) { if (!removeSet.contains((Long)source)) { temp[i++] = source; } } } else { for (long source : sourceArray) { if (!arrayContains(removeArray, source)) { temp[i++] = source; } } } if (i < temp.length) { return Arrays.copyOf(temp, i); } else { return temp; } } private  ArrayUtil(); }
ArrayUtil { public static long[] removeAll(long[] sourceArray, long[] removeArray) { int sourceLength = sourceArray.length; int removeLength = removeArray.length; if (sourceLength == 0 || removeLength == 0) { return sourceArray; } long[] temp = new long[sourceLength]; int i = 0; if (removeLength > 2) { Set<Long> removeSet = new HashSet<Long>(removeLength); for (long remove : removeArray) { removeSet.add((Long)remove); } for (long source : sourceArray) { if (!removeSet.contains((Long)source)) { temp[i++] = source; } } } else { for (long source : sourceArray) { if (!arrayContains(removeArray, source)) { temp[i++] = source; } } } if (i < temp.length) { return Arrays.copyOf(temp, i); } else { return temp; } } private  ArrayUtil(); static Long[] toLongArr(String[] strArr); static Long[] toLongArr(long[] longArr); static long[] toRawLongArr(String[] strArr); static int[] toRawIntArr(String strArr[]); static long[] toLongArr(Collection<Long> ids); static int[] toIntArr(Collection<Integer> ids); static String[] splitSimpleString(String str); static String toSimpleString(long a[]); static void reverse(long[] b); static void reverse(long[][] b); static long[] reverseCopy(long[] original, int newLength); static long[] reverseCopyRange(long[] original, int from, int to); static long[] removeAll(long[] sourceArray, long[] removeArray); static long[] removeAll(long[] sourceArray, Set<Long> removeSet); static long[] sort(long left[], long right[]); static void sortDesc(long[] a); static long[] intersectionOrder(long[] arr1, long[] arr2); static long[] addTo(long[] left, long[] right); static long[] addTo(long[] arr, long id); static long[] addTo(long[] arr, long id, int limit); static long[] getLimited(long[] arr, int limit); }
ArrayUtil { public static long[] removeAll(long[] sourceArray, long[] removeArray) { int sourceLength = sourceArray.length; int removeLength = removeArray.length; if (sourceLength == 0 || removeLength == 0) { return sourceArray; } long[] temp = new long[sourceLength]; int i = 0; if (removeLength > 2) { Set<Long> removeSet = new HashSet<Long>(removeLength); for (long remove : removeArray) { removeSet.add((Long)remove); } for (long source : sourceArray) { if (!removeSet.contains((Long)source)) { temp[i++] = source; } } } else { for (long source : sourceArray) { if (!arrayContains(removeArray, source)) { temp[i++] = source; } } } if (i < temp.length) { return Arrays.copyOf(temp, i); } else { return temp; } } private  ArrayUtil(); static Long[] toLongArr(String[] strArr); static Long[] toLongArr(long[] longArr); static long[] toRawLongArr(String[] strArr); static int[] toRawIntArr(String strArr[]); static long[] toLongArr(Collection<Long> ids); static int[] toIntArr(Collection<Integer> ids); static String[] splitSimpleString(String str); static String toSimpleString(long a[]); static void reverse(long[] b); static void reverse(long[][] b); static long[] reverseCopy(long[] original, int newLength); static long[] reverseCopyRange(long[] original, int from, int to); static long[] removeAll(long[] sourceArray, long[] removeArray); static long[] removeAll(long[] sourceArray, Set<Long> removeSet); static long[] sort(long left[], long right[]); static void sortDesc(long[] a); static long[] intersectionOrder(long[] arr1, long[] arr2); static long[] addTo(long[] left, long[] right); static long[] addTo(long[] arr, long id); static long[] addTo(long[] arr, long id, int limit); static long[] getLimited(long[] arr, int limit);  }