Created
July 10, 2013 14:39
-
-
Save lichenbo/5966850 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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