Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused generateSymmetricHighlighting #11375

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions src/main/java/org/jabref/gui/mergeentries/DiffHighlighting.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@

import com.github.difflib.DiffUtils;
import com.github.difflib.patch.AbstractDelta;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DiffHighlighting {

private static final Logger LOGGER = LoggerFactory.getLogger(DiffHighlighting.class);

private DiffHighlighting() {
}

Expand Down Expand Up @@ -76,36 +72,4 @@ public static Text forRemoved(String text) {
node.getStyleClass().add("text-removed");
return node;
}

public static List<Text> generateSymmetricHighlighting(String baseString, String modifiedString, String separator) {
List<String> stringList = Arrays.asList(baseString.split(separator));
List<Text> result = stringList.stream().map(text -> DiffHighlighting.forUnchanged(text + separator)).collect(Collectors.toList());
List<AbstractDelta<String>> deltaList = DiffUtils.diff(stringList, Arrays.asList(modifiedString.split(separator))).getDeltas();
Collections.reverse(deltaList);
for (AbstractDelta<String> delta : deltaList) {
int startPos = delta.getSource().getPosition();
List<String> lines = delta.getSource().getLines();
int offset = 0;
switch (delta.getType()) {
case CHANGE:
for (String line : lines) {
result.set(startPos + offset, forChanged(line + separator));
offset++;
}
break;
case DELETE:
for (String line : lines) {
result.set(startPos + offset, forAdded(line + separator));
offset++;
}
break;
case INSERT:
break;
default:
break;
}
}

return result;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.jabref.gui.mergeentries;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -94,84 +93,4 @@ void generateDiffHighlightingSingleWordDeleteTextCharacterDiff() {
),
DiffHighlighting.generateDiffHighlighting("foobar", "foo", ""));
}

@Test
void generateSymmetricHighlightingSingleWordAddTextWordDiff() {
assertEquals(
Collections.singletonList(DiffHighlighting.forChanged("foo ")),
DiffHighlighting.generateSymmetricHighlighting("foo", "foobar", " "));
}

@Test
void generateSymmetricHighlightingSingleWordAddTextCharacterDiff() {
assertEquals(
Arrays.asList(
DiffHighlighting.forUnchanged("f"),
DiffHighlighting.forUnchanged("o"),
DiffHighlighting.forUnchanged("o")
),
DiffHighlighting.generateSymmetricHighlighting("foo", "foobar", ""));
}

@Test
void generateSymmetricHighlightingSingleWordDeleteTextWordDiff() {
assertEquals(
Collections.singletonList(DiffHighlighting.forChanged("foobar ")),
DiffHighlighting.generateSymmetricHighlighting("foobar", "foo", " "));
}

@Test
void generateSymmetricHighlightingSingleWordDeleteTextCharacterDiff() {
assertEquals(
Arrays.asList(
DiffHighlighting.forUnchanged("f"),
DiffHighlighting.forUnchanged("o"),
DiffHighlighting.forUnchanged("o"),
DiffHighlighting.forAdded("b"),
DiffHighlighting.forAdded("a"),
DiffHighlighting.forAdded("r")
),
DiffHighlighting.generateSymmetricHighlighting("foobar", "foo", ""));
}

@Test
void generateSymmetricHighlightingMultipleWordsDeleteTextCharacterDiff() {
assertEquals(
Arrays.asList(
DiffHighlighting.forUnchanged("f"),
DiffHighlighting.forUnchanged("o"),
DiffHighlighting.forUnchanged("o"),
DiffHighlighting.forAdded("b"),
DiffHighlighting.forAdded("a"),
DiffHighlighting.forAdded("r"),
DiffHighlighting.forUnchanged(" "),
DiffHighlighting.forUnchanged("a"),
DiffHighlighting.forUnchanged("n"),
DiffHighlighting.forUnchanged("d"),
DiffHighlighting.forUnchanged(" "),
DiffHighlighting.forAdded("s"),
DiffHighlighting.forAdded("o"),
DiffHighlighting.forAdded("m"),
DiffHighlighting.forAdded("e"),
DiffHighlighting.forUnchanged("t"),
DiffHighlighting.forUnchanged("h"),
DiffHighlighting.forUnchanged("i"),
DiffHighlighting.forUnchanged("n"),
DiffHighlighting.forUnchanged("g")
),
DiffHighlighting.generateSymmetricHighlighting("foobar and something", "foo and thing", ""));
}

@Test
void generateSymmetricHighlightingMultipleWordsDeleteTextWordDiff() {
assertEquals(
Arrays.asList(
DiffHighlighting.forUnchanged("foo "),
DiffHighlighting.forAdded("bar "),
DiffHighlighting.forUnchanged("and "),
DiffHighlighting.forAdded("some "),
DiffHighlighting.forUnchanged("thing ")
),
DiffHighlighting.generateSymmetricHighlighting("foo bar and some thing", "foo and thing", " "));
}
}
Loading