add method retainAll

This commit is contained in:
2017-11-10 10:03:10 +01:00
parent 81e1d1f131
commit a59db6cfe8
2 changed files with 54 additions and 4 deletions

View File

@@ -261,6 +261,26 @@ public final class IntList implements Serializable, Cloneable {
index = insertPosition;
}
/**
* Retains all elements contained in the specified list.
*
* @param retain
* the elements to retain
*/
public void retainAll(final IntList retain) {
final int size = index;
int insertPosition = 0;
for (int i = 0; i < size; i++) {
final int current = data[i];
if (retain.indexOf(current) >= 0) {
// keep current element
data[insertPosition] = current;
insertPosition++;
}
}
index = insertPosition;
}
/**
* Replaces all values in the list by applying {@code operator}.
*