Adding isBlank method (#89)

* added isBlank method, along with junit test and readme update

* removing local files

* adding gitignore with Eclipse specific files ignored

* removed unused imports from Strman.java and split tests out to match current test convention
This commit is contained in:
Andy Deese
2017-05-20 06:57:21 +05:30
committed by Shekhar Gulati
parent cf1d373442
commit d04e679b07
4 changed files with 44 additions and 2 deletions
+5
View File
@@ -71,3 +71,8 @@ hs_err_pid*
!gradle/wrapper/gradle-wrapper.jar
/bin/
.classpath
.project
.settings
+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).
+11
View File
@@ -1305,6 +1305,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 +1335,6 @@ public abstract class Strman {
}
return countSubstr(value.substring(offset), subStr, allowOverlapping, ++count);
}
}
+15 -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,19 @@ public class StrmanTest {
assertThat(charsCount("-----abbcccCCCBBA-----"), equalTo(expectedOutput));
}
@Test
public void isBlank_shouldReturnTrueIfNull() {
assertTrue(isBlank(null));
}
@Test
public void isBlank_shouldReturnTrueIfEmpty() {
assertTrue(isBlank(""));
}
@Test
public void isBlank_shouldReturnFalseIfNotEmpty() {
assertFalse(isBlank("ac"));
}
}