add method removeIf

This commit is contained in:
2017-11-10 10:35:51 +01:00
parent b50cb8fdca
commit 88e0179dd5
3 changed files with 119 additions and 7 deletions

View File

@@ -0,0 +1,56 @@
package org.lucares.collections;
import java.util.function.Predicate;
/**
* A {@link Predicate} for primitive integers.
*/
@FunctionalInterface
public interface IntPredicate {
/**
* Evaluates the predicate.
*
* @param i
* the input argument
* @return {@code true} iff the input argument matches the predicate
*/
boolean test(int i);
/**
* Returns a predicate that represents the logical AND of {@code this} and
* another predicate. The and operation is short-circuiting.
*
* @param other
* the other predicate
* @return the result of combining both predicates with a logical AND operation
* @throws NullPointerException
* if {@code other} is null
*/
default IntPredicate and(final IntPredicate other) {
return (t) -> test(t) && other.test(t);
}
/**
* Returns a predicate that represents the logical OR of {@code this} and
* another predicate. The and operation is short-circuiting.
*
* @param other
* the other predicate
* @return the result of combining both predicates with a logical OR operation
* @throws NullPointerException
* if {@code other} is null
*/
default IntPredicate or(final IntPredicate other) {
return (t) -> test(t) || other.test(t);
}
/**
* Returns a predicate that negates the result of this predicate.
*
* @return the negation of {@code this}
*/
default IntPredicate negate() {
return (t) -> !test(t);
}
}