de.tsl2.nano.replication.util.ULog Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tsl2.nano.replication Show documentation
Show all versions of tsl2.nano.replication Show documentation
Provides Database/XML Replication through JPA
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;
}
}