Skip to content

Commit

Permalink
Replace custom predicates with the ones from JDK #270
Browse files Browse the repository at this point in the history
  • Loading branch information
andrus committed Mar 24, 2024
1 parent 0e74395 commit a30a493
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions dflib/src/main/java/org/dflib/Predicates.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,31 @@
import java.util.function.Predicate;

/**
* Contains static helper methods to create some useful predicates.
* Contains static methods to create a few useful predicates.
*
* @since 1.0.0-M21
*/
public final class Predicates {

public static Predicate<Object> isTrue() {
return o -> {

if (o instanceof Boolean) {
return ((Boolean) o).booleanValue();
}

String s = o != null ? o.toString() : null;

// null-safe... "parseBoolean" returns false for null
return Boolean.parseBoolean(s);
};
}

public static BoolValueMapper<String> isTrueString() {
// null-safe... "parseBoolean" returns false for null
return s -> Boolean.parseBoolean(s);
}

public static <T> Predicate<T> isIn(T... values) {

if (values.length == 0) {
Expand All @@ -29,7 +48,7 @@ public static <T> Predicate<T> isIn(T... values) {
return set::contains;
}

static <T> Predicate<T> isIn(Iterable<? extends T> values) {
public static <T> Predicate<T> isIn(Iterable<? extends T> values) {

// index for faster lookups
Set<T> set;
Expand Down

0 comments on commit a30a493

Please sign in to comment.