private int numberOf(K k, Node root) {
        if (root == null) return 0;
        if (k.compareTo(root.value) > 0)
            return numberOf(k, root.right);
        else if (k.compareTo(root.value) < 0)
            return numberOf(k, root.left);
        else
            return root.duplicateCount;
    }
This is another version of binary search tree with support of duplicates.
Idea: store extra variable that counts the number of duplicates in each node.
src/ds/BSTWithDuplicate.java