All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.hyperfoil.controller.WriterUtil Maven / Gradle / Ivy

There is a newer version: 0.27.1
Show newest version
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