code: public static <N extends TreeNode<N>> int countNodes(N tree) {
  	int result = 0;
  	if (tree == null) {
  	    return result;
  	}
  	List<N> children = tree.getChildren();
  	for (N node : children) {
  	    result += countNodes(node);
  	}
  	return result + 1; // + 1 for self!
      }
docs: This method counts all nodes within a tree.
  
  @param tree
  is a {@link TreeNode} object which nodes are to be calculated.
  @param <N>
  is the actual tree implementation.
  @return An integer is returned containing the number of nodes. If tree is
  <code>null</code> 0 is returned.