
io.hyperfoil.controller.WriterUtil Maven / Gradle / Ivy
package io.hyperfoil.controller;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
class WriterUtil {
static void printInSync(Map> map, ThrowingBiConsumer consumer) throws E {
String[] addresses = map.keySet().toArray(new String[0]);
@SuppressWarnings("unchecked")
Iterator[] iterators = Stream.of(addresses).map(a -> map.get(a).iterator()).toArray(Iterator[]::new);
boolean hadNext;
do {
hadNext = false;
for (int i = 0; i < addresses.length; ++i) {
if (iterators[i].hasNext()) {
consumer.accept(addresses[i], iterators[i].next());
hadNext = true;
}
}
} while (hadNext);
}
@FunctionalInterface
interface ThrowingBiConsumer {
void accept(A a, B b) throws E;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy