mirror of
https://github.com/shekhargulati/strman-java.git
synced 2026-10-20 14:34:04 +00:00
Fixed #18. Added support for removeEmptyStrings function
This commit is contained in:
@@ -654,6 +654,19 @@ public abstract class Strman {
|
||||
return joiner.toString() + value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove empty Strings from string array
|
||||
*
|
||||
* @param strings Array of String to be cleaned
|
||||
* @return Array of String without empty Strings
|
||||
*/
|
||||
public static String[] removeEmptyStrings(String[] strings) {
|
||||
if (Objects.isNull(strings)) {
|
||||
throw new IllegalArgumentException("Input array should not be null");
|
||||
}
|
||||
return Arrays.stream(strings).filter(str -> str != null && !str.trim().isEmpty()).toArray(String[]::new);
|
||||
}
|
||||
|
||||
public static String decode(final String value, final int digits, final int radix) {
|
||||
validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
|
||||
return Arrays
|
||||
|
||||
@@ -9,6 +9,7 @@ import static java.util.stream.Collectors.toList;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.hasItems;
|
||||
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.format;
|
||||
@@ -498,4 +499,9 @@ public class StrmanTest {
|
||||
assertThat(prependArray("bar", new String[]{"foo"}), equalTo("foobar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeEmptyStrings_shouldRemoveEmptyStrings() throws Exception {
|
||||
assertThat(removeEmptyStrings(new String[]{"aa", "", " ", "bb", "cc", null}), arrayContaining("aa", "bb", "cc"));
|
||||
assertThat(removeEmptyStrings(new String[0]), emptyArray());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user