add method removeAll

This commit is contained in:
2017-11-09 14:32:15 +01:00
parent db6ca1387d
commit 81e1d1f131
2 changed files with 64 additions and 1 deletions

View File

@@ -23,7 +23,6 @@ public final class IntList implements Serializable, Cloneable {
// TODO add retainAll for sorted lists
// TODO add removeAll for sorted lists
// TODO add removeIf
// TODO add removeRange
// TODO add replace
// TODO add lastIndexOf
// TODO remove bounds checks that are handled by java, e.g. negative indices
@@ -83,6 +82,19 @@ public final class IntList implements Serializable, Cloneable {
index = intList.size();
}
/**
* Create a new {@link IntList} with a copy of the given elements.
*
* @param values
* the values
* @return the list
*/
public static IntList of(final int... values) {
final IntList result = new IntList(values.length);
result.addAll(values);
return result;
}
/**
* Returns {@code true} if this list contains no elements.
*
@@ -228,6 +240,27 @@ public final class IntList implements Serializable, Cloneable {
index = index - (toIndex - fromIndex);
}
/**
* Remove all elements that contained in the specified list.
*
* @param remove
* the elements to remove
*/
public void removeAll(final IntList remove) {
final int size = index;
int insertPosition = 0;
for (int i = 0; i < size; i++) {
final int current = data[i];
if (remove.indexOf(current) < 0) {
// keep current element
data[insertPosition] = current;
insertPosition++;
}
}
index = insertPosition;
}
/**
* Replaces all values in the list by applying {@code operator}.
*