public static <T>Optional<T> lowestCommonAncestor(TreeDef.Parented<T> treeDef,List<T> nodes){
  if (nodes.size() == 0) {
    return Optional.empty();
  }
 else {
    Optional<T> soFar=Optional.of(nodes.get(0));
    for (int i=1; i < nodes.size() && soFar.isPresent(); ++i) {
      soFar=lowestCommonAncestor(treeDef,soFar.get(),nodes.get(i));
    }
    return soFar;
  }
}

public static < T > Optional < T > lowestCommonAncestor ( TreeDef . Parented < T > treeDef , List < T > nodes ) { if ( nodes . size ( ) == 0 ) { return Optional . empty ( ) ; } else { Optional < T > soFar = Optional . of ( nodes . get ( 0 ) ) ; for ( int i = 1 ; i < nodes . size ( ) && soFar . isPresent ( ) ; ++ i ) { soFar = lowestCommonAncestor ( treeDef , soFar . get ( ) , nodes . get ( i ) ) ; } return soFar ; } }
returns the common parent of n elements .
