private int getDepth(T item) { int depth = -1; while (item != null) { item = getParentOfItem(item); ++depth; } return depth; }
/** * Finds the index of the parent of the item in given target index. * * @param item * the item to get the parent of * @return the parent index or a negative value if the parent is not found * */ public Integer getParentIndex(T item) { // TODO: This can be optimized. List<T> flatHierarchy = getHierarchy(null).collect(Collectors.toList()); return flatHierarchy.indexOf(getParentOfItem(item)); }