@Test public void testMergePathsSmallDeviation() { Block b1=new Block(); Block b2=new Block(); Interaction i1=new Interaction(new Role("P1"), new MessageSignature(new TypeReference("A"))); Interaction i2=new Interaction(new Role("P2"), new MessageSignature(new TypeReference("B"))); Interaction i3=new Interaction(new Role("P2"), new MessageSignature(new TypeReference("C"))); Interaction i4=new Interaction(new Role("P3"), new MessageSignature(new TypeReference("D"))); b1.add(i1); b1.add(i2); b1.add(i4); b2.add(i1); b2.add(i3); b2.add(i4); Block targetPath=new Block(); FeedbackHandler handler=new DefaultFeedbackHandler(); java.util.List<Block> sourcePaths=new java.util.Vector<Block>(); sourcePaths.add(b1); sourcePaths.add(b2); ProtocolAggregatorImpl aggregator=new ProtocolAggregatorImpl(); aggregator.mergePaths(sourcePaths, targetPath, handler); if (targetPath.size() != 3) { fail("Target path should have three components: "+targetPath.size()); } if (!targetPath.get(0).equals(i1)) { fail("First component was unexpected"); } if (!(targetPath.get(1) instanceof Choice)) { fail("Second component should be a choice"); } Choice c=(Choice)targetPath.get(1); if (c.getRole() == null) { fail("Role not set"); } if (!c.getRole().getName().equals("P2")) { fail("Choice role not P2"); } if (c.getPaths().size() != 2) { fail("Two choice paths expected"); } Block rb1=c.getPaths().get(0); if (rb1.size() != 1) { fail("Choice block 1 should only have single entry: "+rb1.size()); } if (!rb1.get(0).equals(i2)) { fail("Choice block 1 should contain i2"); } Block rb2=c.getPaths().get(1); if (rb2.size() != 1) { fail("Choice block 2 should only have single entry: "+rb2.size()); } if (!rb2.get(0).equals(i3)) { fail("Choice block 2 should contain i3"); } if (!targetPath.get(2).equals(i4)) { fail("Third component was unexpected"); } }
protected void mergePaths(java.util.List<Block> sourcePaths, Block targetPath, FeedbackHandler handler) { if (sourcePaths.size() == 0) { return; } else if (sourcePaths.size() == 1) { targetPath.getContents().addAll(sourcePaths.get(0).getContents()); return; } while (transferCommonComponent(targetPath, targetPath.size(), sourcePaths, 0, handler)); if (sourcePaths.size() > 0) { Choice choice=new Choice(); targetPath.add(choice); int pos=targetPath.indexOf(choice); while (transferCommonComponent(targetPath, pos+1, sourcePaths, -1, handler)); boolean optional=false; boolean content=false; while (sourcePaths.size() > 0) { Block path=sourcePaths.get(0); if (path.size() == 0) { optional = true; } else { content = true; Object component=path.get(0); java.util.List<Block> sps=new java.util.Vector<Block>(); sps.add(path); for (int i=1; i < sourcePaths.size(); i++) { Block path2=sourcePaths.get(i); if (path2.size() > 0 && path2.get(0).equals(component)) { sps.add(path2); sourcePaths.remove(i); i--; } } if (sps.size() == 1) { choice.getPaths().add(sps.get(0)); } else { Block tp=new Block(); choice.getPaths().add(tp); mergePaths(sps, tp, handler); } } sourcePaths.remove(0); } if (!content) { targetPath.remove(choice); } else { if (optional) { choice.getPaths().add(new Block()); } Role role=null; for (Block b : choice.getPaths()) { if (b.size() > 0 && b.get(0) instanceof Interaction) { Interaction in=(Interaction)b.get(0); if (in.getFromRole() == null) { role = in.getEnclosingProtocol().getLocatedRole(); break; } else { role = in.getFromRole(); break; } } } choice.setRole(new Role(role)); } } }
ProtocolAggregatorImpl implements ProtocolAggregator { protected void mergePaths(java.util.List<Block> sourcePaths, Block targetPath, FeedbackHandler handler) { if (sourcePaths.size() == 0) { return; } else if (sourcePaths.size() == 1) { targetPath.getContents().addAll(sourcePaths.get(0).getContents()); return; } while (transferCommonComponent(targetPath, targetPath.size(), sourcePaths, 0, handler)); if (sourcePaths.size() > 0) { Choice choice=new Choice(); targetPath.add(choice); int pos=targetPath.indexOf(choice); while (transferCommonComponent(targetPath, pos+1, sourcePaths, -1, handler)); boolean optional=false; boolean content=false; while (sourcePaths.size() > 0) { Block path=sourcePaths.get(0); if (path.size() == 0) { optional = true; } else { content = true; Object component=path.get(0); java.util.List<Block> sps=new java.util.Vector<Block>(); sps.add(path); for (int i=1; i < sourcePaths.size(); i++) { Block path2=sourcePaths.get(i); if (path2.size() > 0 && path2.get(0).equals(component)) { sps.add(path2); sourcePaths.remove(i); i--; } } if (sps.size() == 1) { choice.getPaths().add(sps.get(0)); } else { Block tp=new Block(); choice.getPaths().add(tp); mergePaths(sps, tp, handler); } } sourcePaths.remove(0); } if (!content) { targetPath.remove(choice); } else { if (optional) { choice.getPaths().add(new Block()); } Role role=null; for (Block b : choice.getPaths()) { if (b.size() > 0 && b.get(0) instanceof Interaction) { Interaction in=(Interaction)b.get(0); if (in.getFromRole() == null) { role = in.getEnclosingProtocol().getLocatedRole(); break; } else { role = in.getFromRole(); break; } } } choice.setRole(new Role(role)); } } } }
ProtocolAggregatorImpl implements ProtocolAggregator { protected void mergePaths(java.util.List<Block> sourcePaths, Block targetPath, FeedbackHandler handler) { if (sourcePaths.size() == 0) { return; } else if (sourcePaths.size() == 1) { targetPath.getContents().addAll(sourcePaths.get(0).getContents()); return; } while (transferCommonComponent(targetPath, targetPath.size(), sourcePaths, 0, handler)); if (sourcePaths.size() > 0) { Choice choice=new Choice(); targetPath.add(choice); int pos=targetPath.indexOf(choice); while (transferCommonComponent(targetPath, pos+1, sourcePaths, -1, handler)); boolean optional=false; boolean content=false; while (sourcePaths.size() > 0) { Block path=sourcePaths.get(0); if (path.size() == 0) { optional = true; } else { content = true; Object component=path.get(0); java.util.List<Block> sps=new java.util.Vector<Block>(); sps.add(path); for (int i=1; i < sourcePaths.size(); i++) { Block path2=sourcePaths.get(i); if (path2.size() > 0 && path2.get(0).equals(component)) { sps.add(path2); sourcePaths.remove(i); i--; } } if (sps.size() == 1) { choice.getPaths().add(sps.get(0)); } else { Block tp=new Block(); choice.getPaths().add(tp); mergePaths(sps, tp, handler); } } sourcePaths.remove(0); } if (!content) { targetPath.remove(choice); } else { if (optional) { choice.getPaths().add(new Block()); } Role role=null; for (Block b : choice.getPaths()) { if (b.size() > 0 && b.get(0) instanceof Interaction) { Interaction in=(Interaction)b.get(0); if (in.getFromRole() == null) { role = in.getEnclosingProtocol().getLocatedRole(); break; } else { role = in.getFromRole(); break; } } } choice.setRole(new Role(role)); } } }  }
ProtocolAggregatorImpl implements ProtocolAggregator { protected void mergePaths(java.util.List<Block> sourcePaths, Block targetPath, FeedbackHandler handler) { if (sourcePaths.size() == 0) { return; } else if (sourcePaths.size() == 1) { targetPath.getContents().addAll(sourcePaths.get(0).getContents()); return; } while (transferCommonComponent(targetPath, targetPath.size(), sourcePaths, 0, handler)); if (sourcePaths.size() > 0) { Choice choice=new Choice(); targetPath.add(choice); int pos=targetPath.indexOf(choice); while (transferCommonComponent(targetPath, pos+1, sourcePaths, -1, handler)); boolean optional=false; boolean content=false; while (sourcePaths.size() > 0) { Block path=sourcePaths.get(0); if (path.size() == 0) { optional = true; } else { content = true; Object component=path.get(0); java.util.List<Block> sps=new java.util.Vector<Block>(); sps.add(path); for (int i=1; i < sourcePaths.size(); i++) { Block path2=sourcePaths.get(i); if (path2.size() > 0 && path2.get(0).equals(component)) { sps.add(path2); sourcePaths.remove(i); i--; } } if (sps.size() == 1) { choice.getPaths().add(sps.get(0)); } else { Block tp=new Block(); choice.getPaths().add(tp); mergePaths(sps, tp, handler); } } sourcePaths.remove(0); } if (!content) { targetPath.remove(choice); } else { if (optional) { choice.getPaths().add(new Block()); } Role role=null; for (Block b : choice.getPaths()) { if (b.size() > 0 && b.get(0) instanceof Interaction) { Interaction in=(Interaction)b.get(0); if (in.getFromRole() == null) { role = in.getEnclosingProtocol().getLocatedRole(); break; } else { role = in.getFromRole(); break; } } } choice.setRole(new Role(role)); } } }  ProtocolModel aggregateGlobalModel(String protocolName, String namespace,
				java.util.Collection<ProtocolModel> locals,
							FeedbackHandler handler); ProtocolModel aggregateLocalModel(String protocolName,
				java.util.Collection<ProtocolModel> locals, FeedbackHandler handler); }
ProtocolAggregatorImpl implements ProtocolAggregator { protected void mergePaths(java.util.List<Block> sourcePaths, Block targetPath, FeedbackHandler handler) { if (sourcePaths.size() == 0) { return; } else if (sourcePaths.size() == 1) { targetPath.getContents().addAll(sourcePaths.get(0).getContents()); return; } while (transferCommonComponent(targetPath, targetPath.size(), sourcePaths, 0, handler)); if (sourcePaths.size() > 0) { Choice choice=new Choice(); targetPath.add(choice); int pos=targetPath.indexOf(choice); while (transferCommonComponent(targetPath, pos+1, sourcePaths, -1, handler)); boolean optional=false; boolean content=false; while (sourcePaths.size() > 0) { Block path=sourcePaths.get(0); if (path.size() == 0) { optional = true; } else { content = true; Object component=path.get(0); java.util.List<Block> sps=new java.util.Vector<Block>(); sps.add(path); for (int i=1; i < sourcePaths.size(); i++) { Block path2=sourcePaths.get(i); if (path2.size() > 0 && path2.get(0).equals(component)) { sps.add(path2); sourcePaths.remove(i); i--; } } if (sps.size() == 1) { choice.getPaths().add(sps.get(0)); } else { Block tp=new Block(); choice.getPaths().add(tp); mergePaths(sps, tp, handler); } } sourcePaths.remove(0); } if (!content) { targetPath.remove(choice); } else { if (optional) { choice.getPaths().add(new Block()); } Role role=null; for (Block b : choice.getPaths()) { if (b.size() > 0 && b.get(0) instanceof Interaction) { Interaction in=(Interaction)b.get(0); if (in.getFromRole() == null) { role = in.getEnclosingProtocol().getLocatedRole(); break; } else { role = in.getFromRole(); break; } } } choice.setRole(new Role(role)); } } }  ProtocolModel aggregateGlobalModel(String protocolName, String namespace,
				java.util.Collection<ProtocolModel> locals,
							FeedbackHandler handler); ProtocolModel aggregateLocalModel(String protocolName,
				java.util.Collection<ProtocolModel> locals, FeedbackHandler handler);  }