JAL-4134 - refactor tree calculation code to work with binaryNode base type.