void (@NotNull IntervalNode<T> n1, @NotNull IntervalNode<T> n2) { IntervalNode<T> l1 = n1.getLeft(); IntervalNode<T> r1 = n1.getRight(); IntervalNode<T> p1 = n1.getParent(); IntervalNode<T> l2 = n2.getLeft(); IntervalNode<T> r2 = n2.getRight(); IntervalNode<T> p2 = n2.getParent(); if (p1 != null) { if (p1.getLeft() == n1) p1.setLeft(n2); else p1.setRight(n2); } else { root = n2; } if (p2 != null) { if (p2.getLeft() == n2) p2.setLeft(p2 == n1 ? l2 : n1); else p2.setRight(p2 == n1 ? r2 : n1); } else { root = n1; } n1.setParent(p2 == n1 ? n2 : p2); n2.setParent(p1); n1.setLeft(l2); n2.setLeft(l1 == n2 ? n1 : l1); if (l1 != null) l1.setParent(n2 == l1 ? p1 : n2); if (r1 != null) r1.setParent(n2); n1.setRight(r2); n2.setRight(r1); if (l2 != null) l2.setParent(n1); if (r2 != null) r2.setParent(n1); }