private <T>int findTreeNodeDepth(Map<T,T> tree,T node){
  int result=0;
  T parent=tree.get(node);
  while (parent != null) {
    result++;
    node=parent;
    parent=tree.get(node);
  }
  return result;
}

private < T > int findTreeNodeDepth ( Map < T , T > tree , T node ) { int result = 0 ; T parent = tree . get ( node ) ; while ( parent != null ) { result ++ ; node = parent ; parent = tree . get ( node ) ; } return result ; }
returns the depth of node in tree . root ' s depth is 0 .
