class SimpleReferenceTree implements IndexRuleTree {

    @Override
    public void addIndexRule(String indexRule) {
        if (indexRule == null) {
            throw new IllegalArgumentException("Pattern must not be null");
        }

        StringBuilder rule = new StringBuilder(indexRule);
        TreeNode parentNode = null, childNode = null;

        // Locates the last matching node.
        TreeNode lockNode = findLastMatchingNode(root, rule);

        // Lock on the node to ensure thread safety during tree modifications.
        // FIXME: Synchronisation needs to be reconsidered as this fails with three or more threads.
        synchronized (lockNode) {

            // Verify no additional matching sub-nodes have been added during the lock.
            parentNode = childNode = findLastMatchingNode(lockNode, rule);

            // Build out additional tree nodes.
            for (int index = 0; index < rule.length(); index++) {
                childNode = factory.getTreeNode(rule.charAt(index));
                childNode.setParent(parentNode);
                childNode.setSibling(parentNode.getChild());
                parentNode.setChild(childNode);
                parentNode = childNode;
            }
        }

        // Mark child node.
        childNode.markEndPoint();
    }

    public  SimpleReferenceTree();
    public  SimpleReferenceTree(TreeNodeFactory factory);

}