use of java.util.Spliterator in project j2cl by google.
the class StreamImpl method flatMapToInt.
@Override
public IntStream flatMapToInt(Function<? super T, ? extends IntStream> mapper) {
throwIfTerminated();
final Spliterator<? extends IntStream> spliteratorOfStreams = new MapToObjSpliterator<>(mapper, spliterator);
AbstractIntSpliterator flatMapSpliterator = new Spliterators.AbstractIntSpliterator(Long.MAX_VALUE, 0) {
IntStream nextStream;
Spliterator.OfInt next;
@Override
public boolean tryAdvance(IntConsumer action) {
// look for a new spliterator
while (advanceToNextSpliterator()) {
// if we have one, try to read and use it
if (next.tryAdvance(action)) {
return true;
} else {
nextStream.close();
nextStream = null;
// failed, null it out so we can find another
next = null;
}
}
return false;
}
private boolean advanceToNextSpliterator() {
while (next == null) {
if (!spliteratorOfStreams.tryAdvance(n -> {
if (n != null) {
nextStream = n;
next = n.spliterator();
}
})) {
return false;
}
}
return true;
}
};
return new IntStreamImpl(this, flatMapSpliterator);
}
use of java.util.Spliterator in project cx-flow by checkmarx-ltd.
the class AzureDevopsClient method getProjectIssueIds.
private List<String> getProjectIssueIds() throws IOException {
log.info("Getting project issue IDs.");
ObjectNode requestBody = objectMapper.createObjectNode();
// WIQL language is read-only, so potential parameter injection shouldn't do any harm.
String wiqlQuery = String.format("Select System.Id From WorkItems Where System.TeamProject = '%s'", projectName);
requestBody.put("query", wiqlQuery);
HttpEntity<ObjectNode> request = getRequestEntity(requestBody);
String url = getResourceUrl("wit/wiql", null);
ResponseEntity<ObjectNode> response = restClient.exchange(url, HttpMethod.POST, request, ObjectNode.class);
ObjectNode responseBody = extractBody(response);
List<String> result = StreamSupport.stream(responseBody.get("workItems").spliterator(), false).map(issue -> issue.get(ID_KEY).asText()).collect(Collectors.toList());
log.info("Issues found: {}", result.size());
return result;
}
use of java.util.Spliterator in project baremaps by baremaps.
the class PartitionedSpliteratorTest method trySplitWithNonEquivalentElementInStreamTest.
@Test
void trySplitWithNonEquivalentElementInStreamTest() {
PartitionedSpliterator<Integer> stream = new PartitionedSpliterator<>(IntStream.range(0, 600).spliterator(), 250);
Spliterator<Stream<Integer>> a = stream.trySplit();
Spliterator<Stream<Integer>> b = stream.trySplit();
Spliterator<Stream<Integer>> c = stream.trySplit();
Spliterator<Stream<Integer>> d = stream.trySplit();
AtomicInteger i = new AtomicInteger();
a.forEachRemaining(s -> s.forEach(item -> {
// cast necessary otherwise call is ambiguous
assertEquals(i.get(), (long) item);
i.getAndIncrement();
}));
b.forEachRemaining(s -> s.forEach(item -> {
assertEquals(i.get(), (long) item);
i.getAndIncrement();
}));
c.forEachRemaining(s -> s.forEach(item -> {
assertEquals(i.get(), (long) item);
i.getAndIncrement();
}));
d.forEachRemaining(s -> s.forEach(item -> fail()));
stream.forEachRemaining(item -> fail());
assertEquals(600, i.get());
}
use of java.util.Spliterator in project geotoolkit by Geomatys.
the class DistanceSpliteratorTest method testSegments.
private void testSegments(final CoordinateReferenceSystem crs, final boolean isOrthodromic) throws IOException, FactoryException {
final DistanceSpliterator.Builder builder = DistanceSpliterator.builder().setCrs(crs);
final UnaryOperator<Coordinate> pointTransformer = getTransformer(crs);
final List<Segment> segments = Segment.loadTestData();
for (Segment s : segments) {
builder.setPolyline(new CoordinateArraySequence(new Coordinate[] { pointTransformer.apply(s.start), pointTransformer.apply(s.end) }, 2));
final Spliterator.OfDouble ds = isOrthodromic ? builder.buildOrthodromic() : builder.buildLoxodromic();
Assert.assertEquals("Returned spliterator is not of expected type", DistanceSpliterator.class, ds.getClass());
boolean segmentComputed = ds.tryAdvance((double val) -> EngineTest.assertDistance(s, isOrthodromic, val));
Assert.assertTrue("Segment length has not been computed", segmentComputed);
ds.tryAdvance((double val) -> org.junit.Assert.fail("A second computing has been done, despite the fact that we've got only one segment."));
}
}
use of java.util.Spliterator in project structure-project by wudskq.
the class IntPipeline method forEachWithCancel.
@Override
final void forEachWithCancel(Spliterator<Integer> spliterator, Sink<Integer> sink) {
Spliterator.OfInt spl = adapt(spliterator);
IntConsumer adaptedSink = adapt(sink);
do {
} while (!sink.cancellationRequested() && spl.tryAdvance(adaptedSink));
}
Aggregations