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

de.tsl2.nano.replication.util.ULog Maven / Gradle / Ivy

There is a newer version: 2.5.1
Show newest version
package de.tsl2.nano.replication.util;

import java.util.Arrays;
import java.util.Optional;
import java.util.function.Supplier;

public class ULog {
	public static  T call(String txt, LSupplier...callbacks) throws Exception {
		long start = System.currentTimeMillis();
		log(txt + "...", false, null);
		Optional result = Arrays.stream(callbacks).map(c -> c.get()).findFirst();
		System.out.println((System.currentTimeMillis() - start) + " ms");
		return result.get();
	}
	public static void log(String txt) {
		log(txt, true);
	}
	public static void log(String txt, boolean newline, Object...args) {
		System.out.print(String.format(txt, args) + (newline ? "\n" : ""));
	}

	@FunctionalInterface
	public interface LSupplier extends Supplier {
		@Override
		default T get() {
			try {
				return getAndThrow();
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		T getAndThrow() throws Exception;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy