public RBNode<T> delete(RBNode<T> z) {
		RBNode<T> leftChild = z.getLeftChild();
		RBNode<T> rightChild = z.getRightChild();
		RBNode<T> zParent = z.getParent();

		if (leftChild == null && rightChild == null) { // 1. if node is leaf
			// if zParent is null then z was root node
			if (zParent == null) {
				root = null;
				z.setParent(null);
			} else {
				boolean zWasLeft = z.equals(zParent.getLeftChild());

				zParent.deleteChild(z);
				z.setParent(null);
				if (z.getColor() == RBNode.COLOR_NODE_BLACK) { // 1.1 if leaf
																// was black fix
																// up the tree

					deleteFixUp(z, zParent, zWasLeft);
				}
			}
//			size--;
			return z;

		} else if (leftChild != null && rightChild != null) { // 3. if the z
																// node has two
																// children
			RBNode<T> successor = treeSuccessor(z);

			// replaceNode(z, successor);
			// replace z node by successor
			Object zValue = z.getValue();
			// T zKey = z.getKey();
			// int zColor = z.getColor();
			z.setValue(successor.getValue());
			// z.setColor(successor.getColor());
			successor.setValue(zValue);
			// successor.setColor(zColor);

			// RBNode<T> successorRightChild = successor.getRightChild();

			RBNode<T> returnObject = delete(successor);

			// set color of successor child
			// int oldSuccessorColor = successor.getColor();
			// if (successorRightChild != null) {
			// successorRightChild.setColor(successor.getColor());
			// successor.setColor(z.getColor());
			// }

			// maybe we do not need this
			// because we changed the color of successor child to successor
			// color
			// if (oldSuccessorColor == RBNode.COLOR_NODE_BLACK) {
			// boolean zWasLeft = (zParent == null) ? false :
			// z.equals(zParent.getLeftChild());
			//
			// deleteFixUp(z, zParent, zWasLeft);
			// }
//			size--;
			return returnObject;

		} else {/* if (leftChild != null || rightChild != null) */// 2. if node
																	// has only
																	// one child
			RBNode<T> child = null;
			if (leftChild != null) { // if node has only left child
				child = leftChild;
				z.setLeftChild(null);
			} else { // if node has only right child
				child = rightChild;
				z.setRightChild(null);
			}

			if (zParent == null) {
				root = child;
			} else if (zParent.getLeftChild().equals(z)) { // if z was left
															// child
				zParent.setLeftChild(child);
			} else { /* if (zParent.getRightChild().equals(z)) */// if z was
																// right child
				zParent.setRightChild(child);
			}

			child.setParent(zParent);
			z.setParent(null);

			child.setColor(z.getColor());

//			size--;
			return z;
		}
	}