IntBinaryTreeUsage { public Integer max(IntBinaryTree tree) { return tree.match(new IntBinaryTree.MatchBlock<Integer>() { @Override public Integer _case(Node x) { final Integer maxLeft = max(x.left); final int l = maxLeft == null ? Integer.MIN_VALUE : maxLeft; final Integer maxRight = max(x.right); final int r = maxRight == null ? Integer.MIN_VALUE : maxRight; return Math.max(Math.max(l, r), x.value); } @Override public Integer _case(EmptyTree x) { return null; } }); }  IntBinaryTree createExample(); Integer max(IntBinaryTree tree);  }
@Test public void testMax() { final IntBinaryTreeUsage usage = new IntBinaryTreeUsage(); assertEquals(null, usage.max(_EmptyTree())); assertEquals(Integer.valueOf(110), usage.max(_Node(42, _Node(12, _EmptyTree(), _EmptyTree()), _Node(103, _EmptyTree(), _Node(110, _EmptyTree(), _EmptyTree()))))); }