conductor / stream-utils Goto Github PK
View Code? Open in Web Editor NEWA collection of utilities for Java 8 Streams
Home Page: https://www.conductor.com/
License: Apache License 2.0
A collection of utilities for Java 8 Streams
Home Page: https://www.conductor.com/
License: Apache License 2.0
Not necessarily a bug, a nice to have. Would be nice to not have to manage the lifecycle of streams that come through a join.
would be nice to be able to release new versions automatically.
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()));
}
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.
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]);
}
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);
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.