@SuppressWarnings("unchecked") public Sentry unionWithSentries(Sentry a, Sentry b) { SentryImpl sa = (SentryImpl) a; SentryImpl sb = (SentryImpl) b; if (sa == sb) return sa; if (Math.random() < 0.5) { sa.root = sb; sb.children.add(sa); return sb; } else { sb.root = sa; sa.children.add(sb); return sa; } }
/** * ***************************************************************************************************************** * Private Methods * **************************************************************************************************************** */ private SentryImpl compress(SentryImpl sentry) { if (sentry.root == sentry) return sentry; SentryImpl root = compress(sentry.root); sentry.root = root; return root; }