Coder Social home page Coder Social logo

stream-utils's People

Contributors

benmanbs avatar condevopsjenkins avatar jgangemi avatar rkm5112 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stream-utils's Issues

switchIfEmpty doesn't work if the replacement stream is of length 1

here's a test that proves the bug:

    @Test
    public void testSwitchIfEmpty_endlessLoop() {
        final Stream<Integer> integerStream = StreamUtils.switchIfEmpty(Stream.empty(), () -> Stream.of(1));
        assertEquals(Collections.singletonList(1), integerStream.collect(Collectors.toList()));
    }

Possible NPE in comparator

If your comparator doesn't handle nulls, and you pass in an empty stream, you're gonna have a bad time.

Even if your streams are both non-empty, if one is longer than the other there exists the possibility of NPE.

switchIfEmpty util doesn't properly close replacement streams

unit test:

    @Test
    public void testSwitchIfEmptyProperlyClosesReplacementStream() {
        final boolean[] closed = new boolean[] { false };
        final Stream<Integer> replacementStream = Stream.of(1, 2, 3)
                .onClose(() -> {
                    closed[0] = true;
                });
        final Stream<Integer> integerStream = StreamUtils.switchIfEmpty(Stream.empty(), () -> replacementStream);
        assertEquals(Arrays.asList(1, 2, 3), integerStream.collect(Collectors.toList()));
        integerStream.close();
        assertTrue(closed[0]);
    }

switchIfEmpty has a bug in how it handles exceptions

Read the test case:

    @Test
    public void doesNotThrowExceptionUntilNextCall_whenHasNextReturnsTrueButNextThrows() {
        // this test validates that if attempting to retrieve an item throws
        // an exception, that exception is not thrown until the appropriate
        // next/peek call happens.
        // in this instance, the delegate is actually returning "true" when
        // asked if it has next, and then calling next throws an exception.
        // we want to preserve that behavior
        when(mockIterator.hasNext()).thenReturn(true);
        when(mockIterator.next()).thenThrow(new RuntimeException());

        assertTrue(peekingIterator.hasNext());
        boolean caught = false;
        try {
            peekingIterator.peek();
        } catch(Exception e) {
            caught = true;
        }
        assertTrue(caught);
        caught = false;
        try {
            peekingIterator.next();
        } catch(Exception e) {
            caught = true;
        }
        assertTrue(caught);
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.