package dslab.util; import dslab.rmi.serialize.Executors.ThrowingRunnable; import java.util.Collection; import java.util.List; import java.util.logging.Logger; import static java.lang.System.out; import static java.util.stream.Collectors.joining; public class Utils { private static final Logger LOG = Logger.getLogger(Utils.class.getSimpleName()); public static String listElements(Collection collection) { return collection.stream().map(Object::toString).collect(joining(",")); } /** * List.of("foo","bar") |-> * "1. foo * 2. bar" */ public static void printListing(List list) { if (list.isEmpty()) out.println(""); else for (int i = 0; i < list.size(); i++) out.println(i + 1 + ". " + list.get(i)); } public static void asUnchecked(ThrowingRunnable runnable) throws RuntimeException { try {runnable.run();} catch (Exception e) {throw new RuntimeException(e);} } }