import java.util.*; import java.util.zip.*; import java.util.List; import java.util.regex.*; import java.util.concurrent.*; import java.util.concurrent.atomic.*; import java.util.concurrent.locks.*; import java.util.function.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.text.*; import javax.swing.table.*; import java.io.*; import java.net.*; import java.lang.reflect.*; import java.lang.ref.*; import java.lang.management.*; import java.security.*; import java.security.spec.*; import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.awt.geom.*; import javax.imageio.*; import java.math.*; import java.time.Duration; import java.lang.invoke.VarHandle; import java.lang.invoke.MethodHandles; class main { // assumes that each set function is called only once static class PairCollector { volatile A a; volatile B b; volatile int counter; // statically get var handles private static final VarHandle vhA, vhB, vhCounter; static { try { var l = MethodHandles.lookup(); vhA = l.findVarHandle(PairCollector.class, "a", Object.class); vhB = l.findVarHandle(PairCollector.class, "b", Object.class); vhCounter = l.findVarHandle(PairCollector.class, "counter", int.class); } catch (Exception __e) { throw rethrow(__e); } } void setA(A a) { this.a = a; incCounter(); } void setB(B b) { this.b = b; incCounter(); } IVF1 setterForA() { return a -> setA(a); } IVF1 setterForB() { return b -> setB(b); } private void incCounter() { if (((int) vhCounter.getAndAdd(this, 1))+1 == 2) complete(a, b); } // can override or swap transient IVF2 complete; void complete(A a, B b) { if (complete != null) complete.get(a, b); else complete_base(a, b); } final void complete_fallback(IVF2 _f, A a, B b) { if (_f != null) _f.get(a, b); else complete_base(a, b); } void complete_base(A a, B b) {} } static RuntimeException rethrow(Throwable t) { if (t instanceof Error) _handleError((Error) t); throw t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t); } static RuntimeException rethrow(String msg, Throwable t) { throw new RuntimeException(msg, t); } static void _handleError(Error e) { //call(javax(), '_handleError, e); } static interface IVF1 { void get(A a); } static interface IVF2 { void get(A a, B b); } }