DATAGEODE-302 - Add 'nullSafeIsEmpty(:Stream) utility method to StreamUtils.
This commit is contained in:
@@ -61,6 +61,18 @@ public abstract class StreamUtils {
|
||||
return nullSafeStream(stream).count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Null-safe utility method used to determine whether the given {@link Stream} is empty.
|
||||
*
|
||||
* @param stream {@link Stream} to evalute.
|
||||
* @return a boolean value indicating whether the given {@link Stream} is empty.
|
||||
* @see java.util.stream.Stream
|
||||
* @see #nullSafeCount(Stream)
|
||||
*/
|
||||
public static boolean nullSafeIsEmpty(Stream<?> stream) {
|
||||
return nullSafeCount(stream) == 0L;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method used to guard against {@literal null} {@link Stream Streams}.
|
||||
*
|
||||
|
||||
@@ -106,6 +106,26 @@ public class StreamUtilsUnitTests {
|
||||
assertThat(StreamUtils.nullSafeCount(Stream.of(1, 2))).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isEmptyWithNullStream() {
|
||||
assertThat(StreamUtils.nullSafeIsEmpty(null)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isEmptyWithEmptyStream() {
|
||||
assertThat(StreamUtils.nullSafeIsEmpty(Stream.empty())).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isEmptyWithOneElementStream() {
|
||||
assertThat(StreamUtils.nullSafeIsEmpty(Stream.of(1))).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isEmptyWithTwoElementStream() {
|
||||
assertThat(StreamUtils.nullSafeIsEmpty(Stream.of(1, 2))).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullSafeStreamWithStream() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user