code: public static <T extends HierarchyEntity<T, ?>> void addParent(Collection<T> nodes, T toRoot) {
      Set<T> parents = CollectUtils.newHashSet();
      for (T node : nodes) {
        while (null != node.getParent() && !parents.contains(node.getParent())
            && !Objects.equals(node.getParent(), toRoot)) {
          parents.add(node.getParent());
          node = node.getParent();
        }
      }
      nodes.addAll(parents);
    }
docs: <p>
  addParent.
  </p>
  
  @param nodes a {@link java.util.Collection} object.
  @param toRoot a T object.
  @param <T> a T object.