/** * Normalize the process model. By default this may do nothing. * * @return The model (this). */ public M normalize(SplitFactory<? extends T, M> splitFactory) { ensureIds(); // Make all nodes directly refer to other nodes. for (T childNode : mProcessNodes) { childNode.resolveRefs(); } for (T childNode : mProcessNodes) { // Create a copy as we are actually going to remove all successors, but need to keep the list ArrayList<Identifiable> successors = new ArrayList<>(childNode.getSuccessors()); if (successors.size() > 1 && !(childNode instanceof Split)) { for (Identifiable suc2 : successors) { // Remove the current node as predecessor. ProcessNode<?, ?> suc = (ProcessNode) suc2; suc.removePredecessor(childNode); childNode.removeSuccessor(suc); // remove the predecessor from the current node } // create a new join, this should Split<? extends T, M> newSplit = splitFactory.createSplit(asM(), successors); childNode.addSuccessor(newSplit); } } return this.asM(); }