Skip to content

Commit

Permalink
fix: Used generic predictaes for null check
Browse files Browse the repository at this point in the history
Signed-off-by: ABHIJEET SHUKLA <[email protected]>
  • Loading branch information
abhijeetshuklaoist committed Feb 1, 2021
1 parent e2849d9 commit ef07a12
Showing 1 changed file with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
import java.util.TreeMap;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -135,14 +133,10 @@ public static List<String[]> splitOnLastColon(List<String> listToSplit) {
return Collections.emptyList();
}

private static final Predicate<String> NOT_EMPTY = s -> s != null && !s.isEmpty();

private static final UnaryOperator<String> TRIM = s -> s != null ? s.trim() : null;

private static final Function<String, List<String>> COMMA_SPLITTER =
input -> Arrays.stream(input.split(COMMA))
.map(TRIM)
.filter(NOT_EMPTY)
.filter(StringUtils::isNotBlank)
.map(StringUtils::trim)
.collect(Collectors.toList());

/**
Expand All @@ -156,7 +150,7 @@ public static List<String> removeEmptyEntries(@Nullable List<String> input) {
if (input == null) {
return Collections.emptyList();
}
return input.stream().map(TRIM).filter(NOT_EMPTY).collect(Collectors.toList());
return input.stream().filter(StringUtils::isNotBlank).map(StringUtils::trim).collect(Collectors.toList());
}

/**
Expand All @@ -171,7 +165,7 @@ public static List<String> splitAtCommasAndTrim(Iterable<String> input) {
return Collections.emptyList();
}
return StreamSupport.stream(input.spliterator(), false)
.filter(NOT_EMPTY).map(COMMA_SPLITTER).flatMap(Collection::stream)
.filter(StringUtils::isNotBlank).map(COMMA_SPLITTER).flatMap(Collection::stream)
.collect(Collectors.toList());
}

Expand Down

0 comments on commit ef07a12

Please sign in to comment.