Set assignedNodes=new HashSet();
Map implMap=new HashMap();
Set<Dependency> predecessors=new HashSet<Dependency>();
Set<Dependency> successors=new HashSet<Dependency>();
for (ListIterator i=parentNodes.listIterator();i.hasNext();){
Node parent=(Node)i.next();
Node newParent=cloneNode(parent,null,implMap,predecessors,successors);
cloneBranch(parent,newParent,assignedNodes,implMap,predecessors,successors);
i.remove();
i.add(newParent);
}
//rebuild dependencies
if (Environment.isKeepExternalLinks()){
for (Dependency dependency : successors) {
TaskLinkReference pt=(TaskLinkReference)dependency.getPredecessor();
TaskLinkReference st=(TaskLinkReference)dependency.getSuccessor();
HasDependencies predecessor=(Task)implMap.get(pt);
HasDependencies successor=(Task)implMap.get(st);
if (predecessor==null) predecessor=new TaskLinkReferenceImpl(pt.getUniqueId(),pt.getProject());
if (successor==null) successor=new TaskLinkReferenceImpl(st.getUniqueId(),st.getProject());
Dependency d=Dependency.getInstance(predecessor, successor, dependency.getDependencyType(), dependency.getLag());
d.setDirty(true);
predecessor.getDependencyList(false).add(d);
successor.getDependencyList(true).add(d);
predecessors.remove(d);
}
for (Dependency dependency : predecessors) {
TaskLinkReference pt=(TaskLinkReference)dependency.getPredecessor();
TaskLinkReference st=(TaskLinkReference)dependency.getSuccessor();
TaskLinkReference predecessor=(TaskLinkReference)implMap.get(pt);
TaskLinkReference successor=(TaskLinkReference)implMap.get(st);
if (predecessor==null) predecessor=new TaskLinkReferenceImpl(pt.getUniqueId(),pt.getProject());
if (successor==null) successor=new TaskLinkReferenceImpl(st.getUniqueId(),st.getProject());
Dependency d=Dependency.getInstance(predecessor, successor, dependency.getDependencyType(), dependency.getLag());
d.setDirty(true);
predecessor.getDependencyList(false).add(d);
successor.getDependencyList(true).add(d);
//successors.remove(d);
}
}else{
for (Dependency dependency : predecessors) {
if (successors.contains(dependency)){
Task predecessor=(Task)implMap.get(dependency.getPredecessor());
Task successor=(Task)implMap.get(dependency.getSuccessor());
if (predecessor!=null&&successor!=null){
Dependency d=Dependency.getInstance(predecessor, successor, dependency.getDependencyType(), dependency.getLag());
d.setDirty(true);
//Serializer.connectDependency(dependency, predecessor, successor);
predecessor.getDependencyList(false).add(d);
successor.getDependencyList(true).add(d);
}
}
}
}
for (Iterator i=assignedNodes.iterator();i.hasNext();){
addAssignments((Node)i.next());
}
for (ListIterator i=parentNodes.listIterator();i.hasNext();){
Node node=(Node)i.next();
cleanBranch(node);
}
return parentNodes;
}