mirror of
https://github.com/shekhargulati/strman-java.git
synced 2026-10-22 16:23:44 +00:00
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:
committed by
Shekhar Gulati
parent
cf1d373442
commit
d04e679b07
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user