Skip to content

Instantly share code, notes, and snippets.

@lichenbo
Created July 10, 2013 14:39
Show Gist options
  • Select an option

  • Save lichenbo/5966850 to your computer and use it in GitHub Desktop.

Select an option

Save lichenbo/5966850 to your computer and use it in GitHub Desktop.
private boolean batchRemove(Collection<?> c, boolean complement) {
final Object[] elementData = this.elementData;
int r = 0, w = 0;
boolean modified = false;
try {
for (; r < size; r++)
if (c.contains(elementData[r]) == complement)
elementData[w++] = elementData[r];
} finally {
// Preserve behavioral compatibility with AbstractCollection,
// even if c.contains() throws.
if (r != size) {
System.arraycopy(elementData, r,
elementData, w,
size - r);
w += size - r;
}
if (w != size) {
for (int i = w; i < size; i++)
elementData[i] = null;
modCount += size - w;
size = w;
modified = true;
}
}
return modified;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment