added isBlank method, along with junit test and readme update

This commit is contained in:
Andy Deese
2017-05-19 09:18:15 -04:00
parent cf1d373442
commit 1877634234
7 changed files with 69 additions and 2 deletions
+14
View File
@@ -38,6 +38,9 @@ import static java.util.function.Function.identity;
import static java.util.stream.Collectors.counting;
import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.joining;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static strman.Strman.isBlank;
/**
* A String manipulation library without any dependencies
@@ -1305,6 +1308,16 @@ public abstract class Strman {
.mapToObj(c -> (char) c)
.collect(groupingBy(identity(), counting()));
}
/**
* Checks if string is empty. This is a null safe check and will return true when string is null.
*
* @param input The input string
* @return true if string is null or empty
*/
public static boolean isBlank(String input) {
return input == null || input.isEmpty();
}
private static void validate(String value, Predicate<String> predicate, final Supplier<String> supplier) {
if (predicate.test(value)) {
@@ -1325,5 +1338,6 @@ public abstract class Strman {
}
return countSubstr(value.substring(offset), subStr, allowOverlapping, ++count);
}
}