private void fixAfterDeletion(OMVRBTreeEntry<K, V> x) {
    while (x != root && colorOf(x) == BLACK) {
      if (x == leftOf(parentOf(x))) {
        OMVRBTreeEntry<K, V> sib = rightOf(parentOf(x));

        if (colorOf(sib) == RED) {
          setColor(sib, BLACK);
          setColor(parentOf(x), RED);
          rotateLeft(parentOf(x));
          sib = rightOf(parentOf(x));
        }

        if (colorOf(leftOf(sib)) == BLACK && colorOf(rightOf(sib)) == BLACK) {
          setColor(sib, RED);
          x = parentOf(x);
        } else {
          if (colorOf(rightOf(sib)) == BLACK) {
            setColor(leftOf(sib), BLACK);
            setColor(sib, RED);
            rotateRight(sib);
            sib = rightOf(parentOf(x));
          }
          setColor(sib, colorOf(parentOf(x)));
          setColor(parentOf(x), BLACK);
          setColor(rightOf(sib), BLACK);
          rotateLeft(parentOf(x));
          x = root;
        }
      } else { // symmetric
        OMVRBTreeEntry<K, V> sib = leftOf(parentOf(x));

        if (colorOf(sib) == RED) {
          setColor(sib, BLACK);
          setColor(parentOf(x), RED);
          rotateRight(parentOf(x));
          sib = leftOf(parentOf(x));
        }

        if (x != null && colorOf(rightOf(sib)) == BLACK && colorOf(leftOf(sib)) == BLACK) {
          setColor(sib, RED);
          x = parentOf(x);
        } else {
          if (colorOf(leftOf(sib)) == BLACK) {
            setColor(rightOf(sib), BLACK);
            setColor(sib, RED);
            rotateLeft(sib);
            sib = leftOf(parentOf(x));
          }
          setColor(sib, colorOf(parentOf(x)));
          setColor(parentOf(x), BLACK);
          setColor(leftOf(sib), BLACK);
          rotateRight(parentOf(x));
          x = root;
        }
      }
    }

    setColor(x, BLACK);
  }
private void fixAfterDeletion ( OMVRBTreeEntry < K , V > x ) { while ( x != root && colorOf ( x ) == BLACK ) { if ( x == leftOf ( parentOf ( x ) ) ) { OMVRBTreeEntry < K , V > sib = rightOf ( parentOf ( x ) ) ; if ( colorOf ( sib ) == RED ) { setColor ( sib , BLACK ) ; setColor ( parentOf ( x ) , RED ) ; rotateLeft ( parentOf ( x ) ) ; sib = rightOf ( parentOf ( x ) ) ; } if ( colorOf ( leftOf ( sib ) ) == BLACK && colorOf ( rightOf ( sib ) ) == BLACK ) { setColor ( sib , RED ) ; x = parentOf ( x ) ; } else { if ( colorOf ( rightOf ( sib ) ) == BLACK ) { setColor ( leftOf ( sib ) , BLACK ) ; setColor ( sib , RED ) ; rotateRight ( sib ) ; sib = rightOf ( parentOf ( x ) ) ; } setColor ( sib , colorOf ( parentOf ( x ) ) ) ; setColor ( parentOf ( x ) , BLACK ) ; setColor ( rightOf ( sib ) , BLACK ) ; rotateLeft ( parentOf ( x ) ) ; x = root ; } } else { OMVRBTreeEntry < K , V > sib = leftOf ( parentOf ( x ) ) ; if ( colorOf ( sib ) == RED ) { setColor ( sib , BLACK ) ; setColor ( parentOf ( x ) , RED ) ; rotateRight ( parentOf ( x ) ) ; sib = leftOf ( parentOf ( x ) ) ; } if ( x != null && colorOf ( rightOf ( sib ) ) == BLACK && colorOf ( leftOf ( sib ) ) == BLACK ) { setColor ( sib , RED ) ; x = parentOf ( x ) ; } else { if ( colorOf ( leftOf ( sib ) ) == BLACK ) { setColor ( rightOf ( sib ) , BLACK ) ; setColor ( sib , RED ) ; rotateLeft ( sib ) ; sib = leftOf ( parentOf ( x ) ) ; } setColor ( sib , colorOf ( parentOf ( x ) ) ) ; setColor ( parentOf ( x ) , BLACK ) ; setColor ( leftOf ( sib ) , BLACK ) ; rotateRight ( parentOf ( x ) ) ; x = root ; } } } setColor ( x , BLACK ) ; }
From CLR