class CaseManagementCommandUtil {

    @SuppressWarnings("unchecked")
    public static int getChildCanvasIndex(final Node<View<?>, Edge> parent,
                                          final Node<View<?>, Edge> child) {
        if (parent != null && child != null) {
            List<Edge> outEdges = parent.getOutEdges();
            if (null != outEdges && !outEdges.isEmpty()) {
                Predicate<Node> predicate = (Objects.isNull(parent.getContent())
                        || !(parent.getContent().getDefinition() instanceof CaseManagementDiagram))
                        ? CaseManagementCommandUtil::isSubStageNode : CaseManagementCommandUtil::isStageNode;

                for (int i = 0, c = 0, n = outEdges.size(); i < n; i++) {
                    final Node cNode = outEdges.get(i).getTargetNode();
                    if (child.equals(cNode)) {
                        return c;
                    }

                    if (predicate.test(cNode)) {
                        c++;
                    }
                }
            }
        }
        return -1;
    }

}