class Splitting {

    public boolean checkValidTopology(TTopologyTemplate topologyTemplate) {
        Map<TNodeTemplate, Set<TNodeTemplate>> transitiveAndDirectSuccessors = computeTransitiveClosure(topologyTemplate);

        //check if the highest level node templates have target labels assigned
        for (TNodeTemplate node : getNodeTemplatesWithoutIncomingHostedOnRelationships(topologyTemplate)) {
            if (!ModelUtilities.getTargetLabel(node).isPresent()) {
                return false;
            }
        }

        //check the transitive closure for each node if nodes with different labels are reachable by hostedOn relationships
        for (TNodeTemplate node : transitiveAndDirectSuccessors.keySet()) {
            if (!transitiveAndDirectSuccessors.get(node).isEmpty()) {
                for (TNodeTemplate successor : transitiveAndDirectSuccessors.get(node)) {
                    if (ModelUtilities.getTargetLabel(successor).isPresent() && ModelUtilities.getTargetLabel(node).isPresent()
                        && !ModelUtilities.getTargetLabel(node).get().equalsIgnoreCase(ModelUtilities.getTargetLabel(successor).get())) {
                        return false;
                    }
                }
            }
        }
        return true;
    }

}