add replaceAll
This commit is contained in:
@@ -27,7 +27,6 @@ public final class IntList implements Serializable, Cloneable {
|
||||
// TODO add replace
|
||||
// TODO add lastIndexOf
|
||||
// TODO remove bounds checks that are handled by java, e.g. negative indices
|
||||
// TODO toString
|
||||
|
||||
private static final long serialVersionUID = 2622570032686034909L;
|
||||
|
||||
@@ -229,6 +228,20 @@ public final class IntList implements Serializable, Cloneable {
|
||||
index = index - (toIndex - fromIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces all values in the list by applying {@code operator}.
|
||||
*
|
||||
* @param operator
|
||||
* the operator
|
||||
*/
|
||||
public void replaceAll(final UnaryIntOperator operator) {
|
||||
final int size = index;
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
data[i] = operator.apply(data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the element at position {@code pos}.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.lucares.collections;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Represents an operation that maps an int to an int. This is a specialization
|
||||
* of {@link Function} for a primitive integer.
|
||||
*/
|
||||
public interface UnaryIntOperator {
|
||||
/**
|
||||
* Applies the operation to the integer
|
||||
*
|
||||
* @param value
|
||||
* the input value
|
||||
* @return the result of the operation
|
||||
*/
|
||||
int apply(int value);
|
||||
}
|
||||
Reference in New Issue
Block a user