// Path: src/main/java/rogeriogentil/data/structures/chapter07/Position.java
// public interface Position<E> {
//     
//     /**
//      * Returns the element stored at this position.
//      * 
//      * @return An element
//      * @throws IllegalStateException if position no longer valid
//      */
//     E getElement() throws IllegalStateException;
// }
// 
// Path: src/main/java/rogeriogentil/data/structures/chapter09/Entry.java
// public interface Entry<K, V> {
// 
//    /**
//     * Returns the key stored in this entry
//     *
//     * @return
//     */
//    K getKey();
// 
//    /**
//     * Returns the value stored in this entry
//     *
//     * @return
//     */
//    V getvalue();
// }


import java.util.Comparator;
import rogeriogentil.data.structures.chapter07.Position;
import rogeriogentil.data.structures.chapter09.Entry;
            uncle = sibling(parent);
            if (isBlack(uncle)) {                           // Case 1: misshapen 4-node
                middle = restructure(position);             // do trinode restructuring
                makeBlack(middle);
                makeRed(left(middle));
                makeRed(right(middle));
            } else {                                        // Case 2: overfull 5-node
                makeBlack(parent);                          // perform recoloring
                makeBlack(uncle);
                grand = parent(parent);
                if (!isRoot(grand)) {
                    makeRed(grand);                         // grandparent becomes red
                    resolvedRed(grand);                     // recur at red grandparent
                }
            }
        }
    }

    /**
     * Overrides the TreeMap rebalancing hook that is called after a deletion.
     * 
     * @param position 
     */
    @Override
    protected void rebalanceDelete(Position<Entry<K, V>> position) {
        if (isRed(position)) {                              // deleted parent was black
            makeBlack(position);                            // so this restores black depth
        } else if (!isRoot(position)) {
            Position<Entry<K, V>> sibling = sibling(position);
            if (isInternal(sibling) && (isBlack(sibling) || isInternal(left(sibling)))) {
// Path: src/main/java/rogeriogentil/data/structures/chapter07/Position.java
// public interface Position<E> {
//     
//     /**
//      * Returns the element stored at this position.
//      * 
//      * @return An element
//      * @throws IllegalStateException if position no longer valid
//      */
//     E getElement() throws IllegalStateException;
// }
// 
// Path: src/main/java/rogeriogentil/data/structures/chapter09/Entry.java
// public interface Entry<K, V> {
// 
//    /**
//     * Returns the key stored in this entry
//     *
//     * @return
//     */
//    K getKey();
// 
//    /**
//     * Returns the value stored in this entry
//     *
//     * @return
//     */
//    V getvalue();
// }


// Path: src/main/java/rogeriogentil/data/structures/chapter11/RBTreeMap.java
import java.util.Comparator;
import rogeriogentil.data.structures.chapter07.Position;
import rogeriogentil.data.structures.chapter09.Entry;

            uncle = sibling(parent);
            if (isBlack(uncle)) {                           // Case 1: misshapen 4-node
                middle = restructure(position);             // do trinode restructuring
                makeBlack(middle);
                makeRed(left(middle));
                makeRed(right(middle));
            } else {                                        // Case 2: overfull 5-node
                makeBlack(parent);                          // perform recoloring
                makeBlack(uncle);
                grand = parent(parent);
                if (!isRoot(grand)) {
                    makeRed(grand);                         // grandparent becomes red
                    resolvedRed(grand);                     // recur at red grandparent
                }
            }
        }
    }

    /**
     * Overrides the TreeMap rebalancing hook that is called after a deletion.
     * 
     * @param position 
     */
    @Override
    protected void rebalanceDelete(Position<Entry<K, V>> position) {
        if (isRed(position)) {                              // deleted parent was black
            makeBlack(position);                            // so this restores black depth
        } else if (!isRoot(position)) {
            Position<Entry<K, V>> sibling = sibling(position);
            if (isInternal(sibling) && (isBlack(sibling) || isInternal(left(sibling)))) {
                remedyDoubleBlack(position);        // sibling's subtree has nonzero black height