package valhalla.vector; import jdk.experimental.value.ValueType; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.concurrent.Callable; import java.util.stream.Stream; public class Utils { static void assertEquals(Object o1, Object o2) { if ((o1 == null && o2 != null) || !o1.equals(o2)) { throw new AssertionError(o1 + " not equals to " + o2); } } public interface RunnableWithThrowable { void run() throws Throwable; } public static void run(RunnableWithThrowable r) { try { r.run(); } catch (Throwable e) { throw new Error(e); } } public interface CallableWithThrowable { T call() throws Throwable; } public static T compute(CallableWithThrowable c) { try { return c.call(); } catch (Throwable e) { throw new Error(e); } } // Copied from jdk.experimental.value.ValueType public static Field[] valueFields(ValueType vt) { int valFieldMask = Modifier.FINAL; return Stream.of(vt.sourceClass().getDeclaredFields()) .filter(f -> (f.getModifiers() & (valFieldMask | Modifier.STATIC)) == valFieldMask) .toArray(Field[]::new); } }