mirror of
https://github.com/shekhargulati/strman-java.git
synced 2026-10-20 14:34:04 +00:00
added isBlank method, along with junit test and readme update
This commit is contained in:
@@ -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>
|
||||
@@ -71,3 +71,4 @@ hs_err_pid*
|
||||
|
||||
!gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
/bin/
|
||||
|
||||
@@ -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
|
||||
@@ -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).
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user