@Test void mergeCharOnConflicts() throws Exception { MergeResult<Character> result; Conflict<Character> conflict; MergeConfiguration<Character> mergeConfiguration; List<Character> emptyList = Collections.emptyList(); List<Character> onlyA = toCharacters("a"); List<Character> onlyB = toCharacters("b"); List<Character> onlyC = toCharacters("c"); mergeConfiguration = null; result = this.diffManager.merge(onlyA, emptyList, onlyB, mergeConfiguration); conflict = createConflict(0, Type.CHANGE, 0, 0, onlyA, onlyB, Type.CHANGE, 0, 0, onlyA, emptyList); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(onlyB, result.getMerged()); mergeConfiguration = new MergeConfiguration<>(); result = this.diffManager.merge(onlyA, emptyList, onlyB, mergeConfiguration); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(onlyB, result.getMerged()); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.PREVIOUS); result = this.diffManager.merge(onlyA, emptyList, onlyB, mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(onlyA, result.getMerged()); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.NEXT); result = this.diffManager.merge(onlyA, emptyList, onlyB, mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(emptyList, result.getMerged()); mergeConfiguration = null; result = this.diffManager.merge(onlyA, onlyB, onlyC, mergeConfiguration); conflict = createConflict(0, 'a', 'c', 'b'); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(onlyC, result.getMerged()); mergeConfiguration = new MergeConfiguration<>(); result = this.diffManager.merge(onlyA, onlyB, onlyC, mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(onlyC, result.getMerged()); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.PREVIOUS); result = this.diffManager.merge(onlyA, onlyB, onlyC, mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(onlyA, result.getMerged()); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.NEXT); result = this.diffManager.merge(onlyA, onlyB, onlyC, mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(onlyB, result.getMerged()); mergeConfiguration = null; conflict = createConflict(0, Type.CHANGE, 0, 0, Arrays.asList('a', 'b'), Arrays.asList('a', 'z'), Type.CHANGE, 0, 0, Arrays.asList('a', 'b'), Arrays.asList('y', 'y')); result = this.diffManager .merge(toCharacters("abcd"), toCharacters("yycd"), toCharacters("azzd"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals("azzd", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); result = this.diffManager .merge(toCharacters("abcd"), toCharacters("yycd"), toCharacters("azzd"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals("azzd", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.PREVIOUS); result = this.diffManager .merge(toCharacters("abcd"), toCharacters("yycd"), toCharacters("azzd"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals("abcd", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.NEXT); result = this.diffManager .merge(toCharacters("abcd"), toCharacters("yycd"), toCharacters("azzd"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals("yycd", toString(result.getMerged())); conflict = createConflict(0, Type.CHANGE, 0, 0, Arrays.asList('a', 'b'), Arrays.asList('y', 'y'), Type.CHANGE, 0, 0, Arrays.asList('a', 'b'), Arrays.asList('a', 'z')); mergeConfiguration = null; result = this.diffManager .merge(toCharacters("abcd"), toCharacters("azzd"), toCharacters("yycd"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals("yycd", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); result = this.diffManager .merge(toCharacters("abcd"), toCharacters("azzd"), toCharacters("yycd"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals("yycd", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.PREVIOUS); result = this.diffManager .merge(toCharacters("abcd"), toCharacters("azzd"), toCharacters("yycd"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals("abcd", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.NEXT); result = this.diffManager .merge(toCharacters("abcd"), toCharacters("azzd"), toCharacters("yycd"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals("azzd", toString(result.getMerged())); conflict = createConflict(0, Type.CHANGE, 0, 0, Arrays.asList('a', 'a', 'b', 'b'), Arrays.asList('d', 'd', 'd', 'd'), Type.CHANGE, 0, 0, Arrays.asList('a', 'a', 'b', 'b'), Arrays.asList('a', 'r', 'r', 'b')); mergeConfiguration = null; result = this.diffManager .merge(toCharacters("aabbcc"), toCharacters("arrbcc"), toCharacters("ddddcc"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals("ddddcc", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); result = this.diffManager .merge(toCharacters("aabbcc"), toCharacters("arrbcc"), toCharacters("ddddcc"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals("ddddcc", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.PREVIOUS); result = this.diffManager .merge(toCharacters("aabbcc"), toCharacters("arrbcc"), toCharacters("ddddcc"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals("aabbcc", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.NEXT); result = this.diffManager .merge(toCharacters("aabbcc"), toCharacters("arrbcc"), toCharacters("ddddcc"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals("arrbcc", toString(result.getMerged())); conflict = createConflict(0, Type.CHANGE, 0, 0, Arrays.asList('a', 'a', 'b', 'b'), Arrays.asList('a', 'r', 'r', 'b'), Type.CHANGE, 0, 0, Arrays.asList('a', 'a', 'b', 'b'), Arrays.asList('d', 'd', 'd', 'd')); mergeConfiguration = null; result = this.diffManager .merge(toCharacters("aabbcc"), toCharacters("ddddcc"), toCharacters("arrbcc"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals("arrbcc", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); result = this.diffManager .merge(toCharacters("aabbcc"), toCharacters("ddddcc"), toCharacters("arrbcc"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals("arrbcc", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.PREVIOUS); result = this.diffManager .merge(toCharacters("aabbcc"), toCharacters("ddddcc"), toCharacters("arrbcc"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals("aabbcc", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.NEXT); result = this.diffManager .merge(toCharacters("aabbcc"), toCharacters("ddddcc"), toCharacters("arrbcc"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals("ddddcc", toString(result.getMerged())); conflict = createConflict(0, Type.CHANGE, 0, 0, Arrays.asList('a', 'a', 'b', 'b'), Arrays.asList('a', 'r', 'r', 'b'), Type.CHANGE, 0, 0, Arrays.asList('a', 'a', 'b', 'b'), Arrays.asList('d', 'd', 'd', 'd')); Conflict<Character> conflict1 = createConflict(7, Type.CHANGE, 7, 7, Arrays.asList('a', 'b'), Arrays.asList('y', 'y'), Type.CHANGE, 7, 7, Arrays.asList('a', 'b'), Arrays.asList('a', 'z')); mergeConfiguration = null; result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(2, result.getLog().getLogs(LogLevel.ERROR).size()); List<LogEvent> logConflicts = new ArrayList<>(result.getLog().getLogs(LogLevel.ERROR)); assertEquals(2, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(conflict1, result.getConflicts().get(1)); assertEquals("arrbcc yycd", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(2, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(logConflicts, result.getLog().getLogs(LogLevel.ERROR)); assertEquals(2, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(conflict1, result.getConflicts().get(1)); assertEquals("arrbcc yycd", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.PREVIOUS); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(2, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(logConflicts, result.getLog().getLogs(LogLevel.ERROR)); assertEquals(2, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(conflict1, result.getConflicts().get(1)); assertEquals("aabbcc abcd", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.NEXT); result = this.diffManager .merge(toCharacters("aabbcc abcd"), toCharacters("ddddcc azzd"), toCharacters("arrbcc yycd"), mergeConfiguration); assertEquals(2, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(logConflicts, result.getLog().getLogs(LogLevel.ERROR)); assertEquals(2, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(conflict1, result.getConflicts().get(1)); assertEquals("ddddcc azzd", toString(result.getMerged())); conflict = createConflict(2, Type.CHANGE, 2, 2, Arrays.asList('c'), Arrays.asList('c', 'd'), Type.CHANGE, 2, 2, Arrays.asList('c'), Arrays.asList('d')); conflict1 = createConflict(4, Type.CHANGE, 4, 4, Arrays.asList('f'), Collections.emptyList(), Type.CHANGE, 4, 4, Arrays.asList('f'), Arrays.asList('f')); mergeConfiguration = null; result = this.diffManager .merge(toCharacters("abcefhik"), toCharacters("abdefgijk"), toCharacters("abcdehijk"), mergeConfiguration); assertEquals(2, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(2, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(conflict1, result.getConflicts().get(1)); assertEquals("abcdehijk", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); result = this.diffManager .merge(toCharacters("abcefhik"), toCharacters("abdefgijk"), toCharacters("abcdehijk"), mergeConfiguration); assertEquals(2, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(2, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(conflict1, result.getConflicts().get(1)); assertEquals("abcdehijk", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.PREVIOUS); result = this.diffManager .merge(toCharacters("abcefhik"), toCharacters("abdefgijk"), toCharacters("abcdehijk"), mergeConfiguration); assertEquals(2, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(2, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(conflict1, result.getConflicts().get(1)); assertEquals("abcefhijk", toString(result.getMerged())); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.NEXT); result = this.diffManager .merge(toCharacters("abcefhik"), toCharacters("abdefgijk"), toCharacters("abcdehijk"), mergeConfiguration); assertEquals(2, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(2, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(conflict1, result.getConflicts().get(1)); assertEquals("abdefgijk", toString(result.getMerged())); mergeConfiguration = null; conflict = createConflict(1, Type.CHANGE, 1, 1, Collections.emptyList(), Arrays.asList('i'), Type.CHANGE, 1, 1, Collections.emptyList(), Arrays.asList('j')); result = this.diffManager .merge(toCharacters("abc"), toCharacters("ajbc"), toCharacters("aibc"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(toCharacters("aibc"), result.getMerged()); mergeConfiguration = new MergeConfiguration<>(); result = this.diffManager .merge(toCharacters("abc"), toCharacters("ajbc"), toCharacters("aibc"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(toCharacters("aibc"), result.getMerged()); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.NEXT); result = this.diffManager .merge(toCharacters("abc"), toCharacters("ajbc"), toCharacters("aibc"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(toCharacters("ajbc"), result.getMerged()); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.PREVIOUS); result = this.diffManager .merge(toCharacters("abc"), toCharacters("ajbc"), toCharacters("aibc"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(toCharacters("abc"), result.getMerged()); mergeConfiguration = null; conflict = createConflict(1, Type.CHANGE, 1, 1, Collections.emptyList(), Arrays.asList('i'), Type.CHANGE, 1, 1, Collections.emptyList(), Arrays.asList('i', 'j')); result = this.diffManager .merge(toCharacters("ab"), toCharacters("aijb"), toCharacters("aib"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(toCharacters("aib"), result.getMerged()); mergeConfiguration = new MergeConfiguration<>(); result = this.diffManager .merge(toCharacters("ab"), toCharacters("aijb"), toCharacters("aib"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(toCharacters("aib"), result.getMerged()); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.NEXT); result = this.diffManager .merge(toCharacters("ab"), toCharacters("aijb"), toCharacters("aib"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(toCharacters("aijb"), result.getMerged()); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.PREVIOUS); result = this.diffManager .merge(toCharacters("ab"), toCharacters("aijb"), toCharacters("aib"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(toCharacters("ab"), result.getMerged()); mergeConfiguration = null; conflict = createConflict(1, Type.CHANGE, 1, 1, Collections.emptyList(), Arrays.asList('i', 'j'), Type.CHANGE, 1, 1, Collections.emptyList(), Arrays.asList('j')); result = this.diffManager .merge(toCharacters("ab"), toCharacters("ajb"), toCharacters("aijb"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(toCharacters("aijb"), result.getMerged()); mergeConfiguration = new MergeConfiguration<>(); result = this.diffManager .merge(toCharacters("ab"), toCharacters("ajb"), toCharacters("aijb"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(toCharacters("aijb"), result.getMerged()); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.NEXT); result = this.diffManager .merge(toCharacters("ab"), toCharacters("ajb"), toCharacters("aijb"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(toCharacters("ajb"), result.getMerged()); mergeConfiguration = new MergeConfiguration<>(); mergeConfiguration.setFallbackOnConflict(MergeConfiguration.Version.PREVIOUS); result = this.diffManager .merge(toCharacters("ab"), toCharacters("ajb"), toCharacters("aijb"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(toCharacters("ab"), result.getMerged()); conflict = this.createConflict(0, Type.CHANGE, 0, 0, Arrays.asList('y'), Arrays.asList('c'), Type.CHANGE, 0, 0, Arrays.asList('y'), Arrays.asList('b')); mergeConfiguration = null; result = this.diffManager .merge(toCharacters("xy"), toCharacters("ab"), toCharacters("ac"), mergeConfiguration); assertEquals(1, result.getLog().getLogs(LogLevel.ERROR).size()); assertEquals(1, result.getConflicts().size()); assertEquals(conflict, result.getConflicts().get(0)); assertEquals(toCharacters("ac"), result.getMerged()); }
@Override public <E> MergeResult<E> merge(List<E> commonAncestor, List<E> next, List<E> current, MergeConfiguration<E> configuration) throws MergeException { DefaultMergeResult<E> mergeResult = new DefaultMergeResult<>(commonAncestor, next, current); DiffResult<E> diffNextResult; try { diffNextResult = diff(commonAncestor, next, null); } catch (DiffException e) { throw new MergeException("Faile to diff between common ancestor and next version", e); } mergeResult.getLog().addAll(diffNextResult.getLog()); Patch<E> patchNext = diffNextResult.getPatch(); if (patchNext.isEmpty()) { return mergeResult; } if (current.isEmpty() && (commonAncestor.isEmpty() || next.isEmpty())) { if (commonAncestor.isEmpty()) { mergeResult.setMerged(next); } else if (next.isEmpty()) { mergeResult.getLog().warn("The modification was already applied"); } } else { DiffResult<E> diffCurrentResult; try { diffCurrentResult = diff(commonAncestor, current, null); } catch (DiffException e) { throw new MergeException("Fail to diff between common ancestor and current version", e); } mergeResult.getLog().addAll(diffCurrentResult.getLog()); Patch<E> patchCurrent = diffCurrentResult.getPatch(); mergeResult.setMerged(new ArrayList<>()); if (patchCurrent.isEmpty()) { mergeResult.setMerged(next); } else if (!current.equals(next) && (isFullyModified(commonAncestor, patchCurrent) || isFullyModified(commonAncestor, patchNext))) { Delta<E> deltaNext = nextElement(patchNext); Delta<E> deltaCurrent = nextElement(patchCurrent); List<ConflictDecision<E>> conflictDecisionList = (configuration != null) ? configuration.getConflictDecisionList() : Collections.emptyList(); int newIndex = applyDecision(conflictDecisionList, mergeResult.getMerged(), 0); if (newIndex == Integer.MIN_VALUE) { logConflict(mergeResult, deltaCurrent, deltaNext, commonAncestor, next, current, 0); mergeResult.setMerged(fallback(commonAncestor, next, current, configuration)); } } else { merge(mergeResult, commonAncestor, next, current, patchNext, patchCurrent, configuration); } } return mergeResult; }
DefaultDiffManager implements DiffManager { @Override public <E> MergeResult<E> merge(List<E> commonAncestor, List<E> next, List<E> current, MergeConfiguration<E> configuration) throws MergeException { DefaultMergeResult<E> mergeResult = new DefaultMergeResult<>(commonAncestor, next, current); DiffResult<E> diffNextResult; try { diffNextResult = diff(commonAncestor, next, null); } catch (DiffException e) { throw new MergeException("Faile to diff between common ancestor and next version", e); } mergeResult.getLog().addAll(diffNextResult.getLog()); Patch<E> patchNext = diffNextResult.getPatch(); if (patchNext.isEmpty()) { return mergeResult; } if (current.isEmpty() && (commonAncestor.isEmpty() || next.isEmpty())) { if (commonAncestor.isEmpty()) { mergeResult.setMerged(next); } else if (next.isEmpty()) { mergeResult.getLog().warn("The modification was already applied"); } } else { DiffResult<E> diffCurrentResult; try { diffCurrentResult = diff(commonAncestor, current, null); } catch (DiffException e) { throw new MergeException("Fail to diff between common ancestor and current version", e); } mergeResult.getLog().addAll(diffCurrentResult.getLog()); Patch<E> patchCurrent = diffCurrentResult.getPatch(); mergeResult.setMerged(new ArrayList<>()); if (patchCurrent.isEmpty()) { mergeResult.setMerged(next); } else if (!current.equals(next) && (isFullyModified(commonAncestor, patchCurrent) || isFullyModified(commonAncestor, patchNext))) { Delta<E> deltaNext = nextElement(patchNext); Delta<E> deltaCurrent = nextElement(patchCurrent); List<ConflictDecision<E>> conflictDecisionList = (configuration != null) ? configuration.getConflictDecisionList() : Collections.emptyList(); int newIndex = applyDecision(conflictDecisionList, mergeResult.getMerged(), 0); if (newIndex == Integer.MIN_VALUE) { logConflict(mergeResult, deltaCurrent, deltaNext, commonAncestor, next, current, 0); mergeResult.setMerged(fallback(commonAncestor, next, current, configuration)); } } else { merge(mergeResult, commonAncestor, next, current, patchNext, patchCurrent, configuration); } } return mergeResult; } }
DefaultDiffManager implements DiffManager { @Override public <E> MergeResult<E> merge(List<E> commonAncestor, List<E> next, List<E> current, MergeConfiguration<E> configuration) throws MergeException { DefaultMergeResult<E> mergeResult = new DefaultMergeResult<>(commonAncestor, next, current); DiffResult<E> diffNextResult; try { diffNextResult = diff(commonAncestor, next, null); } catch (DiffException e) { throw new MergeException("Faile to diff between common ancestor and next version", e); } mergeResult.getLog().addAll(diffNextResult.getLog()); Patch<E> patchNext = diffNextResult.getPatch(); if (patchNext.isEmpty()) { return mergeResult; } if (current.isEmpty() && (commonAncestor.isEmpty() || next.isEmpty())) { if (commonAncestor.isEmpty()) { mergeResult.setMerged(next); } else if (next.isEmpty()) { mergeResult.getLog().warn("The modification was already applied"); } } else { DiffResult<E> diffCurrentResult; try { diffCurrentResult = diff(commonAncestor, current, null); } catch (DiffException e) { throw new MergeException("Fail to diff between common ancestor and current version", e); } mergeResult.getLog().addAll(diffCurrentResult.getLog()); Patch<E> patchCurrent = diffCurrentResult.getPatch(); mergeResult.setMerged(new ArrayList<>()); if (patchCurrent.isEmpty()) { mergeResult.setMerged(next); } else if (!current.equals(next) && (isFullyModified(commonAncestor, patchCurrent) || isFullyModified(commonAncestor, patchNext))) { Delta<E> deltaNext = nextElement(patchNext); Delta<E> deltaCurrent = nextElement(patchCurrent); List<ConflictDecision<E>> conflictDecisionList = (configuration != null) ? configuration.getConflictDecisionList() : Collections.emptyList(); int newIndex = applyDecision(conflictDecisionList, mergeResult.getMerged(), 0); if (newIndex == Integer.MIN_VALUE) { logConflict(mergeResult, deltaCurrent, deltaNext, commonAncestor, next, current, 0); mergeResult.setMerged(fallback(commonAncestor, next, current, configuration)); } } else { merge(mergeResult, commonAncestor, next, current, patchNext, patchCurrent, configuration); } } return mergeResult; }  }
DefaultDiffManager implements DiffManager { @Override public <E> MergeResult<E> merge(List<E> commonAncestor, List<E> next, List<E> current, MergeConfiguration<E> configuration) throws MergeException { DefaultMergeResult<E> mergeResult = new DefaultMergeResult<>(commonAncestor, next, current); DiffResult<E> diffNextResult; try { diffNextResult = diff(commonAncestor, next, null); } catch (DiffException e) { throw new MergeException("Faile to diff between common ancestor and next version", e); } mergeResult.getLog().addAll(diffNextResult.getLog()); Patch<E> patchNext = diffNextResult.getPatch(); if (patchNext.isEmpty()) { return mergeResult; } if (current.isEmpty() && (commonAncestor.isEmpty() || next.isEmpty())) { if (commonAncestor.isEmpty()) { mergeResult.setMerged(next); } else if (next.isEmpty()) { mergeResult.getLog().warn("The modification was already applied"); } } else { DiffResult<E> diffCurrentResult; try { diffCurrentResult = diff(commonAncestor, current, null); } catch (DiffException e) { throw new MergeException("Fail to diff between common ancestor and current version", e); } mergeResult.getLog().addAll(diffCurrentResult.getLog()); Patch<E> patchCurrent = diffCurrentResult.getPatch(); mergeResult.setMerged(new ArrayList<>()); if (patchCurrent.isEmpty()) { mergeResult.setMerged(next); } else if (!current.equals(next) && (isFullyModified(commonAncestor, patchCurrent) || isFullyModified(commonAncestor, patchNext))) { Delta<E> deltaNext = nextElement(patchNext); Delta<E> deltaCurrent = nextElement(patchCurrent); List<ConflictDecision<E>> conflictDecisionList = (configuration != null) ? configuration.getConflictDecisionList() : Collections.emptyList(); int newIndex = applyDecision(conflictDecisionList, mergeResult.getMerged(), 0); if (newIndex == Integer.MIN_VALUE) { logConflict(mergeResult, deltaCurrent, deltaNext, commonAncestor, next, current, 0); mergeResult.setMerged(fallback(commonAncestor, next, current, configuration)); } } else { merge(mergeResult, commonAncestor, next, current, patchNext, patchCurrent, configuration); } } return mergeResult; }  @Override DiffResult<E> diff(List<E> previous, List<E> next, DiffConfiguration<E> diff); @Override MergeResult<E> merge(List<E> commonAncestor, List<E> next, List<E> current,
        MergeConfiguration<E> configuration); }
DefaultDiffManager implements DiffManager { @Override public <E> MergeResult<E> merge(List<E> commonAncestor, List<E> next, List<E> current, MergeConfiguration<E> configuration) throws MergeException { DefaultMergeResult<E> mergeResult = new DefaultMergeResult<>(commonAncestor, next, current); DiffResult<E> diffNextResult; try { diffNextResult = diff(commonAncestor, next, null); } catch (DiffException e) { throw new MergeException("Faile to diff between common ancestor and next version", e); } mergeResult.getLog().addAll(diffNextResult.getLog()); Patch<E> patchNext = diffNextResult.getPatch(); if (patchNext.isEmpty()) { return mergeResult; } if (current.isEmpty() && (commonAncestor.isEmpty() || next.isEmpty())) { if (commonAncestor.isEmpty()) { mergeResult.setMerged(next); } else if (next.isEmpty()) { mergeResult.getLog().warn("The modification was already applied"); } } else { DiffResult<E> diffCurrentResult; try { diffCurrentResult = diff(commonAncestor, current, null); } catch (DiffException e) { throw new MergeException("Fail to diff between common ancestor and current version", e); } mergeResult.getLog().addAll(diffCurrentResult.getLog()); Patch<E> patchCurrent = diffCurrentResult.getPatch(); mergeResult.setMerged(new ArrayList<>()); if (patchCurrent.isEmpty()) { mergeResult.setMerged(next); } else if (!current.equals(next) && (isFullyModified(commonAncestor, patchCurrent) || isFullyModified(commonAncestor, patchNext))) { Delta<E> deltaNext = nextElement(patchNext); Delta<E> deltaCurrent = nextElement(patchCurrent); List<ConflictDecision<E>> conflictDecisionList = (configuration != null) ? configuration.getConflictDecisionList() : Collections.emptyList(); int newIndex = applyDecision(conflictDecisionList, mergeResult.getMerged(), 0); if (newIndex == Integer.MIN_VALUE) { logConflict(mergeResult, deltaCurrent, deltaNext, commonAncestor, next, current, 0); mergeResult.setMerged(fallback(commonAncestor, next, current, configuration)); } } else { merge(mergeResult, commonAncestor, next, current, patchNext, patchCurrent, configuration); } } return mergeResult; }  @Override DiffResult<E> diff(List<E> previous, List<E> next, DiffConfiguration<E> diff); @Override MergeResult<E> merge(List<E> commonAncestor, List<E> next, List<E> current,
        MergeConfiguration<E> configuration);  }