private void collectConflicts() { Map<Tuples._2<SNodeId, String>, List<NodeGroupChange>> mineGroupChanges = arrangeNodeGroupChanges(myMineChangeSet); Map<Tuples._2<SNodeId, String>, List<NodeGroupChange>> repositoryGroupChanges = arrangeNodeGroupChanges(myRepositoryChangeSet); for (Tuples._2<SNodeId, String> nodeRole : SetSequence.fromSet(MapSequence.fromMap(mineGroupChanges).keySet()) .intersect(SetSequence.fromSet(MapSequence.fromMap(repositoryGroupChanges).keySet()))) { List<NodeGroupChange> mine = MapSequence.fromMap(mineGroupChanges).get(nodeRole); List<NodeGroupChange> repository = MapSequence.fromMap(repositoryGroupChanges).get(nodeRole); // This is a quadratic algorithm, it can be optimized to linear, // but it is left for simplicity for (NodeGroupChange m : ListSequence.fromList(mine)) { for (NodeGroupChange r : ListSequence.fromList(repository)) { if (m.getEnd() < r.getBegin() || m.getBegin() > r.getEnd()) { // ok } else { if (nodeGroupChangesSymmetric(m, r)) { addSymmetric(m, r); } else { addPossibleConflict(m, r); } } } } } collectGroupChangesWithOthersConflicts( mineGroupChanges, myMineChangeSet, myRepositoryChangeSet); collectGroupChangesWithOthersConflicts( repositoryGroupChanges, myRepositoryChangeSet, myMineChangeSet); collectPropertyConflicts(); collectReferenceConflicts(); collectSymmetricRootDeletes(); collectConflictingRootAdds(); collectSymmetricImportedModelChanges(); collectSymmetricModuleDependencyChanges(); }
private boolean nodeGroupChangesSymmetric(NodeGroupChange mine, NodeGroupChange repository) { if (mine.getBegin() == repository.getBegin() && mine.getEnd() == repository.getEnd()) { if (mine.getResultEnd() - mine.getResultBegin() == repository.getResultEnd() - repository.getResultBegin()) { List<? extends SNode> myChildren = IterableUtil.asList( myMyModel.getNode(mine.getParentNodeId()).getChildren(mine.getRole())); List<? extends SNode> repositoryChildren = IterableUtil.asList( myRepositoryModel .getNode(repository.getParentNodeId()) .getChildren(repository.getRole())); for (int o = 0; o < mine.getResultEnd() - mine.getResultBegin(); o++) { if (!(SNodeCompare.nodeEquals( myChildren.get(mine.getResultBegin() + o), repositoryChildren.get(repository.getResultBegin() + o)))) { return false; } } return true; } } return false; }