private static Map<Tuples._2<SNodeId, String>, List<NodeGroupChange>> arrangeNodeGroupChanges( ChangeSet changeSet) { Map<Tuples._2<SNodeId, String>, List<NodeGroupChange>> nodeRoleToGroupChanges = MapSequence.fromMap(new HashMap<Tuples._2<SNodeId, String>, List<NodeGroupChange>>()); for (NodeGroupChange change : Sequence.fromIterable(changeSet.getModelChanges(NodeGroupChange.class))) { Tuples._2<SNodeId, String> nodeRole = MultiTuple.<SNodeId, String>from(change.getParentNodeId(), change.getRole()); if (!(MapSequence.fromMap(nodeRoleToGroupChanges).containsKey(nodeRole))) { MapSequence.fromMap(nodeRoleToGroupChanges) .put(nodeRole, ListSequence.fromList(new ArrayList<NodeGroupChange>())); } ListSequence.fromList(MapSequence.fromMap(nodeRoleToGroupChanges).get(nodeRole)) .addElement(change); } return nodeRoleToGroupChanges; }
private static Iterable<SNodeId> getNodeIdsForNodeGroupChange( @NotNull NodeGroupChange ngc, @Nullable Tuples._2<SNodeId, List<SNodeId>> lastParentAndNewChildrenIds) { List<SNodeId> childrenIds; if (lastParentAndNewChildrenIds == null || neq_5iuzi5_a0a1a72(lastParentAndNewChildrenIds._0(), ngc.getParentNodeId())) { List<? extends SNode> children = IterableUtil.asList( ngc.getChangeSet() .getNewModel() .getNode(ngc.getParentNodeId()) .getChildren(ngc.getRole())); childrenIds = ListSequence.fromList(children) .select( new ISelector<SNode, SNodeId>() { public SNodeId select(SNode n) { return n.getNodeId(); } }) .toListSequence(); } else { childrenIds = lastParentAndNewChildrenIds._1(); } return ListSequence.fromList(childrenIds).page(ngc.getResultBegin(), ngc.getResultEnd()); }
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; }