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
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin"/>
</classpath>
+1
View File
@@ -71,3 +71,4 @@ hs_err_pid*
!gradle/wrapper/gradle-wrapper.jar
/bin/
+23
View File
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>strman</name>
<comment>Project strman created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
@@ -0,0 +1,3 @@
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
+13
View File
@@ -618,6 +618,19 @@ join(new String[]{"hello","world","123"}, ";")
// result => "hello;world;123")
```
## isBlank
isEmpty returns true if a string is blank or null and false otherwise.
```java
isBlank("")
// result => true)
isBlank(null)
// result => true)
isBlank("test")
// result => false)
```
## Inspiration
This library is inspired by [dleitee/strman](https://github.com/dleitee/strman).
+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);
}
}
+7 -2
View File
@@ -37,8 +37,6 @@ import static org.hamcrest.collection.IsArrayContainingInOrder.arrayContaining;
import static org.hamcrest.collection.IsArrayWithSize.emptyArray;
import static org.junit.Assert.*;
import static strman.Strman.*;
import static strman.Strman.endsWith;
import static strman.Strman.format;
public class StrmanTest {
@@ -1027,4 +1025,11 @@ public class StrmanTest {
assertThat(charsCount("-----abbcccCCCBBA-----"), equalTo(expectedOutput));
}
@Test
public void testIsBlank() {
assertTrue(isBlank(""));
assertTrue(isBlank(null));
assertFalse(isBlank("ac"));
}
}