diff options
author | Gary Gregory <garydgregory@gmail.com> | 2022-07-16 11:14:44 -0400 |
---|---|---|
committer | Gary Gregory <garydgregory@gmail.com> | 2022-07-16 11:14:44 -0400 |
commit | 152b1777fddc5127e77f9b14637d6abae18eaf05 (patch) | |
tree | f1c1ff59134a46fdc332c3c4dc056cf362ae5868 /src | |
parent | e0818e3383f71ddff62854f85712cb6b7d187c9b (diff) | |
download | apache-commons-lang-152b1777fddc5127e77f9b14637d6abae18eaf05.tar.gz |
Rename new method
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/apache/commons/lang3/stream/Streams.java | 30 | ||||
-rw-r--r-- | src/test/java/org/apache/commons/lang3/stream/StreamsTest.java | 36 |
2 files changed, 33 insertions, 33 deletions
diff --git a/src/main/java/org/apache/commons/lang3/stream/Streams.java b/src/main/java/org/apache/commons/lang3/stream/Streams.java index 720405129..eee85087e 100644 --- a/src/main/java/org/apache/commons/lang3/stream/Streams.java +++ b/src/main/java/org/apache/commons/lang3/stream/Streams.java @@ -530,7 +530,7 @@ public class Streams { * @since 3.13.0 */ public static <T> FailableStream<T> failableStream(final Collection<T> stream) { - return failableStream(toStream(stream)); + return failableStream(of(stream)); } /** @@ -578,7 +578,7 @@ public class Streams { } private static <E> Stream<E> filter(final Collection<E> collection, final Predicate<? super E> predicate) { - return toStream(collection).filter(predicate); + return of(collection).filter(predicate); } /** @@ -597,7 +597,7 @@ public class Streams { * @since 3.13.0 */ public static <E> Stream<E> instancesOf(final Class<? super E> clazz, final Collection<? super E> collection) { - return instancesOf(clazz, toStream(collection)); + return instancesOf(clazz, of(collection)); } @SuppressWarnings("unchecked") // After the isInstance check, we still need to type-cast. @@ -618,6 +618,18 @@ public class Streams { } /** + * Delegates to {@link Collection#stream()} or returns {@link Stream#empty()} if the collection is null. + * + * @param <E> the type of elements in the collection. + * @param collection the collection to stream or null. + * @return {@link Collection#stream()} or {@link Stream#empty()} if the collection is null. + * @since 3.13.0 + */ + public static <E> Stream<E> of(final Collection<E> collection) { + return collection == null ? Stream.empty() : collection.stream(); + } + + /** * Streams the elements of the given enumeration in order. * * @param <E> The enumeration element type. @@ -742,16 +754,4 @@ public class Streams { public static <T extends Object> Collector<T, ?, T[]> toArray(final Class<T> pElementType) { return new ArrayCollector<>(pElementType); } - - /** - * Delegates to {@link Collection#stream()} or returns {@link Stream#empty()} if the collection is null. - * - * @param <E> the type of elements in the collection. - * @param collection the collection to stream or null. - * @return {@link Collection#stream()} or {@link Stream#empty()} if the collection is null. - * @since 3.13.0 - */ - public static <E> Stream<E> toStream(final Collection<E> collection) { - return collection == null ? Stream.empty() : collection.stream(); - } } diff --git a/src/test/java/org/apache/commons/lang3/stream/StreamsTest.java b/src/test/java/org/apache/commons/lang3/stream/StreamsTest.java index 99b34204b..3db2ec794 100644 --- a/src/test/java/org/apache/commons/lang3/stream/StreamsTest.java +++ b/src/test/java/org/apache/commons/lang3/stream/StreamsTest.java @@ -134,13 +134,6 @@ public class StreamsTest extends AbstractLangTest { } @Test - public void testNullSafeStreamNotNull() { - assertEquals(2, Streams.nonNull(Arrays.asList("A", "B")).collect(Collectors.toList()).size()); - assertEquals(2, Streams.nonNull(Arrays.asList(null, "A", null, "B", null)).collect(Collectors.toList()).size()); - assertEquals(0, Streams.nonNull(Arrays.asList(null, null)).collect(Collectors.toList()).size()); - } - - @Test public void testInstanceOfStream() { assertEquals(2, Streams.instancesOf(String.class, Arrays.asList("A", "B")).collect(Collectors.toList()).size()); assertEquals(2, Streams.instancesOf(String.class, Arrays.asList(null, "A", null, "B", null)).collect(Collectors.toList()).size()); @@ -151,6 +144,13 @@ public class StreamsTest extends AbstractLangTest { } @Test + public void testNullSafeStreamNotNull() { + assertEquals(2, Streams.nonNull(Arrays.asList("A", "B")).collect(Collectors.toList()).size()); + assertEquals(2, Streams.nonNull(Arrays.asList(null, "A", null, "B", null)).collect(Collectors.toList()).size()); + assertEquals(0, Streams.nonNull(Arrays.asList(null, null)).collect(Collectors.toList()).size()); + } + + @Test public void testNullSafeStreamNull() { final List<String> input = null; assertEquals(0, Streams.nonNull(input).collect(Collectors.toList()).size()); @@ -164,6 +164,17 @@ public class StreamsTest extends AbstractLangTest { } @Test + public void testOfCollectionNotNull() { + assertEquals(2, Streams.of(Arrays.asList("A", "B")).collect(Collectors.toList()).size()); + } + + @Test + public void testOfCollectionNull() { + final List<String> input = null; + assertEquals(0, Streams.of(input).collect(Collectors.toList()).size()); + } + + @Test public void testOfEnumeration() { final Hashtable<String, Integer> table = new Hashtable<>(); assertEquals(0, Streams.of(table.elements()).count()); @@ -235,15 +246,4 @@ public class StreamsTest extends AbstractLangTest { assertEquals("1", array[2]); } - @Test - public void testToStreamNotNull() { - assertEquals(2, Streams.toStream(Arrays.asList("A", "B")).collect(Collectors.toList()).size()); - } - - @Test - public void testToStreamNull() { - final List<String> input = null; - assertEquals(0, Streams.toStream(input).collect(Collectors.toList()).size()); - } - } |