X Tutup
Skip to content
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
3 changes: 1 addition & 2 deletions src/main/java/com/github/difflib/DiffUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.List;
import java.util.Objects;
import java.util.function.BiPredicate;
import static java.util.stream.Collectors.joining;

/**
* Implements the difference and patching engine
Expand Down Expand Up @@ -143,7 +142,7 @@ private static List<String> compressLines(List<String> lines, String delimiter)
if (lines.isEmpty()) {
return Collections.emptyList();
}
return Collections.singletonList(lines.stream().collect(joining(delimiter)));
return Collections.singletonList(String.join(delimiter, lines));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
/**
* Thrown whenever the differencing engine cannot produce the differences between two revisions of ta text.
*
* @see MyersDiff
* @see difflib.DiffAlgorithm
* @see com.github.difflib.algorithm.myers.MyersDiff
* @see DiffAlgorithmI
*/
public class DifferentiationFailedException extends DiffException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.github.difflib.algorithm.Change;
import com.github.difflib.algorithm.DiffAlgorithmI;
import com.github.difflib.algorithm.DiffAlgorithmListener;
import com.github.difflib.algorithm.DiffException;
import com.github.difflib.patch.DeltaType;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -37,7 +36,7 @@
public class HistogramDiff<T> implements DiffAlgorithmI<T> {

@Override
public List<Change> computeDiff(List<T> source, List<T> target, DiffAlgorithmListener progress) throws DiffException {
public List<Change> computeDiff(List<T> source, List<T> target, DiffAlgorithmListener progress) {
Objects.requireNonNull(source, "source list must not be null");
Objects.requireNonNull(target, "target list must not be null");
if (progress != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private PathNode buildPath(final List<T> orig, final List<T> rev, DiffAlgorithmL
/**
* Constructs a {@link Patch} from a difference path.
*
* @param path The path.
* @param actualPath The path.
* @param orig The original sequence.
* @param rev The revised sequence.
* @return A {@link Patch} script corresponding to the path.
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/com/github/difflib/algorithm/myers/PathNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
* A node in a diffpath.
*
* @author <a href="mailto:juanco@suigeneris.org">Juanco Anez</a>
*
* @see DiffNode
* @see Snake
*
*/
public final class PathNode {

Expand Down Expand Up @@ -78,10 +74,10 @@ public boolean isBootstrap() {
}

/**
* Skips sequences of {@link DiffNode DiffNodes} until a {@link Snake} or bootstrap node is found, or the end of the
* Skips sequences of {@link PathNode PathNodes} until a snake or bootstrap node is found, or the end of the
* path is reached.
*
* @return The next first {@link Snake} or bootstrap node in the path, or <code>null</code> if none found.
* @return The next first {@link PathNode} or bootstrap node in the path, or <code>null</code> if none found.
*/
public final PathNode previousSnake() {
if (isBootstrap()) {
Expand All @@ -102,9 +98,9 @@ public String toString() {
PathNode node = this;
while (node != null) {
buf.append("(");
buf.append(Integer.toString(node.i));
buf.append(node.i);
buf.append(",");
buf.append(Integer.toString(node.j));
buf.append(node.j);
buf.append(")");
node = node.prev;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/difflib/patch/ChangeDelta.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* Describes the change-delta between original and revised texts.
*
* @author <a href="dm.naumenko@gmail.com">Dmitry Naumenko</a>
* @param T The type of the compared elements in the data 'lines'.
* @param <T> The type of the compared elements in the data 'lines'.
*/
public final class ChangeDelta<T> extends AbstractDelta<T> {

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/difflib/patch/Chunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* </p>
*
* @author <a href="dm.naumenko@gmail.com>Dmitry Naumenko</a>
* @param T The type of the compared elements in the 'lines'.
* @param <T> The type of the compared elements in the 'lines'.
*/
public final class Chunk<T> {

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/difflib/patch/DeleteDelta.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* Describes the delete-delta between original and revised texts.
*
* @author <a href="dm.naumenko@gmail.com">Dmitry Naumenko</a>
* @param T The type of the compared elements in the 'lines'.
* @param <T> The type of the compared elements in the 'lines'.
*/
public final class DeleteDelta<T> extends AbstractDelta<T> {

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/difflib/patch/InsertDelta.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* Describes the add-delta between original and revised texts.
*
* @author <a href="dm.naumenko@gmail.com">Dmitry Naumenko</a>
* @param T The type of the compared elements in the 'lines'.
* @param <T> The type of the compared elements in the 'lines'.
*/
public final class InsertDelta<T> extends AbstractDelta<T> {

Expand Down
9 changes: 3 additions & 6 deletions src/main/java/com/github/difflib/patch/Patch.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,17 @@
*/
package com.github.difflib.patch;

import static java.util.Comparator.comparing;
import com.github.difflib.algorithm.Change;
import static com.github.difflib.patch.DeltaType.DELETE;
import static com.github.difflib.patch.DeltaType.INSERT;
import java.util.ArrayList;
import java.util.Collections;
import static java.util.Comparator.comparing;
import java.util.List;
import java.util.ListIterator;

/**
* Describes the patch holding all deltas between the original and revised texts.
*
* @author <a href="dm.naumenko@gmail.com">Dmitry Naumenko</a>
* @param T The type of the compared elements in the 'lines'.
* @param <T> The type of the compared elements in the 'lines'.
*/
public final class Patch<T> {

Expand Down Expand Up @@ -93,7 +90,7 @@ public void addDelta(AbstractDelta<T> delta) {
* @return the deltas
*/
public List<AbstractDelta<T>> getDeltas() {
Collections.sort(deltas, comparing(d -> d.getSource().getPosition()));
deltas.sort(comparing(d -> d.getSource().getPosition()));
return deltas;
}

Expand Down
13 changes: 5 additions & 8 deletions src/main/java/com/github/difflib/text/DiffRowGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ protected final static List<String> splitStringPreserveDelimiter(String str, Pat
*
* @param startPosition the position from which tag should start. The counting start from a zero.
* @param endPosition the position before which tag should should be closed.
* @param tag the tag name without angle brackets, just a word
* @param cssClass the optional css class
* @param tagGenerator the tag generator
*/
static void wrapInTag(List<String> sequence, int startPosition,
int endPosition, Function<Boolean, String> tagGenerator) {
Expand Down Expand Up @@ -179,16 +178,14 @@ public List<DiffRow> generateDiffRows(List<String> original, List<String> revise
* for displaying side-by-side diff.
*
* @param original the original text
* @param revised the revised text
* @param patch the given patch
* @return the DiffRows between original and revised texts
*/
public List<DiffRow> generateDiffRows(final List<String> original, Patch<String> patch) throws DiffException {
List<DiffRow> diffRows = new ArrayList<>();
int endPos = 0;
final List<AbstractDelta<String>> deltaList = patch.getDeltas();
for (int i = 0; i < deltaList.size(); i++) {
AbstractDelta<String> delta = deltaList.get(i);
for (AbstractDelta<String> delta : deltaList) {
Chunk<String> orig = delta.getSource();
Chunk<String> rev = delta.getTarget();

Expand All @@ -199,7 +196,7 @@ public List<DiffRow> generateDiffRows(final List<String> original, Patch<String>
// Inserted DiffRow
if (delta instanceof InsertDelta) {
endPos = orig.last() + 1;
for (String line : (List<String>) rev.getLines()) {
for (String line : rev.getLines()) {
diffRows.add(buildDiffRow(Tag.INSERT, "", line));
}
continue;
Expand All @@ -208,7 +205,7 @@ public List<DiffRow> generateDiffRows(final List<String> original, Patch<String>
// Deleted DiffRow
if (delta instanceof DeleteDelta) {
endPos = orig.last() + 1;
for (String line : (List<String>) orig.getLines()) {
for (String line : orig.getLines()) {
diffRows.add(buildDiffRow(Tag.DELETE, line, ""));
}
continue;
Expand Down Expand Up @@ -401,7 +398,7 @@ public Builder reportLinesUnchanged(final boolean val) {
/**
* Generator for Old-Text-Tags.
*
* @param tag the tag to set. Without angle brackets. Default: span.
* @param generator the tag generator
* @return builder with configured ignoreBlankLines parameter
*/
public Builder oldTag(Function<Boolean, String> generator) {
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/github/difflib/GenerateUnifiedDiffTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.Test;

Expand Down Expand Up @@ -113,8 +113,8 @@ private void verify(List<String> origLines, List<String> revLines,
Patch<String> fromUnifiedPatch = UnifiedDiffUtils.parseUnifiedDiff(unifiedDiff);
List<String> patchedLines;
try {
patchedLines = (List<String>) fromUnifiedPatch.applyTo(origLines);
assertTrue(revLines.size() == patchedLines.size());
patchedLines = fromUnifiedPatch.applyTo(origLines);
assertEquals(revLines.size(), patchedLines.size());
for (int i = 0; i < revLines.size(); i++) {
String l1 = revLines.get(i);
String l2 = patchedLines.get(i);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/github/difflib/TestConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public final class TestConstants {

public static final String BASE_FOLDER_RESOURCES = "target/test-classes/";
/**
* The base folder containing the test files. Ends with {@link #FS}.
* The base folder containing the test files.
*/
public static final String MOCK_FOLDER = BASE_FOLDER_RESOURCES + "/mocks/";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package com.github.difflib.algorithm.jgit;

import com.github.difflib.algorithm.DiffAlgorithmListener;
import com.github.difflib.algorithm.DiffException;
import com.github.difflib.patch.Patch;
import com.github.difflib.patch.PatchFailedException;
import java.util.ArrayList;
Expand Down Expand Up @@ -58,7 +57,7 @@ public void tearDown() {
* Test of diff method, of class HistogramDiff.
*/
@Test
public void testDiff() throws DiffException, PatchFailedException {
public void testDiff() throws PatchFailedException {
List<String> orgList = Arrays.asList("A", "B", "C", "A", "B", "B", "A");
List<String> revList = Arrays.asList("C", "B", "A", "B", "A", "C");
final Patch<String> patch = Patch.generate(orgList, revList, new HistogramDiff().computeDiff(orgList, revList, null));
Expand All @@ -72,7 +71,7 @@ public void testDiff() throws DiffException, PatchFailedException {
}

@Test
public void testDiffWithListener() throws DiffException, PatchFailedException {
public void testDiffWithListener() throws PatchFailedException {
List<String> orgList = Arrays.asList("A", "B", "C", "A", "B", "B", "A");
List<String> revList = Arrays.asList("C", "B", "A", "B", "A", "C");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import static com.github.difflib.DiffUtilsTest.readStringListFromInputStream;
import com.github.difflib.TestConstants;
import com.github.difflib.algorithm.DiffAlgorithmListener;
import com.github.difflib.algorithm.DiffException;
import com.github.difflib.patch.Patch;
import com.github.difflib.patch.PatchFailedException;
import java.io.IOException;
Expand Down Expand Up @@ -58,7 +57,7 @@ public void tearDown() {
}

@Test
public void testPossibleDiffHangOnLargeDatasetDnaumenkoIssue26() throws IOException, DiffException, PatchFailedException {
public void testPossibleDiffHangOnLargeDatasetDnaumenkoIssue26() throws IOException, PatchFailedException {
ZipFile zip = new ZipFile(TestConstants.MOCK_FOLDER + "/large_dataset1.zip");
List<String> original = readStringListFromInputStream(zip.getInputStream(zip.getEntry("ta")));
List<String> revised = readStringListFromInputStream(zip.getInputStream(zip.getEntry("tb")));
Expand Down
X Tutup