From e6fa5938a9a3b3f55adc0cec45e7183c4802412e Mon Sep 17 00:00:00 2001 From: wumpz Date: Wed, 25 Oct 2017 08:49:20 +0200 Subject: [PATCH] included checkstyle source code conventions --- README.md | 22 + java-diff-utils.iml | 58 +-- nb-configuration.xml | 38 +- pom.xml | 451 ++++++++++-------- .../java/com/github/difflib/DiffUtils.java | 39 +- .../com/github/difflib/UnifiedDiffUtils.java | 16 +- .../com/github/difflib/algorithm/Change.java | 1 + .../difflib/algorithm/DiffAlgorithm.java | 8 +- .../DifferentiationFailedException.java | 7 +- .../difflib/algorithm/jgit/HistogramDiff.java | 15 +- .../difflib/algorithm/myers/MyersDiff.java | 18 +- .../difflib/algorithm/myers/PathNode.java | 11 +- .../java/com/github/difflib/patch/Chunk.java | 7 +- .../com/github/difflib/patch/DeleteDelta.java | 2 +- .../java/com/github/difflib/patch/Delta.java | 2 +- .../com/github/difflib/patch/DeltaType.java | 3 +- .../com/github/difflib/patch/InsertDelta.java | 2 +- .../java/com/github/difflib/patch/Patch.java | 10 +- .../java/com/github/difflib/text/DiffRow.java | 3 +- .../github/difflib/text/DiffRowGenerator.java | 2 +- .../com/github/difflib/DiffUtilsTest.java | 15 +- .../difflib/GenerateUnifiedDiffTest.java | 2 - .../com/github/difflib/TestConstants.java | 1 + .../algorithm/jgit/HistogramDiffTest.java | 23 +- .../algorithm/jgit/LRHistogramDiffTest.java | 23 +- .../algorithm/myers/MyersDiffTest.java | 8 +- .../com/github/difflib/patch/PatchTest.java | 2 - .../difflib/text/DiffRowGeneratorTest.java | 49 +- .../github/difflib/text/StringUtilsTest.java | 10 +- 29 files changed, 445 insertions(+), 403 deletions(-) diff --git a/README.md b/README.md index 9b55899..ca9f297 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,8 @@ This is a test ~senctence~**for diffutils**. But it can easily replaced by any other which is better for handing your texts. I have plan to add implementation of some in future. ### Changelog ### + * Version 2.1-SNAPSHOT + * included checkstyle source code conventions * Version 2.0 * switch to maven and removed other artifacts * changed groupid to **com.github.java-diff-utils** due to different forks at github @@ -66,6 +68,26 @@ But it can easily replaced by any other which is better for handing your texts. * Ant build script * Generate output in unified diff format (thanks for Bill James) +## Source Code conventions + +Recently a checkstyle process was integrated into the build process. JSqlParser follows the sun java format convention. There are no TABs allowed. Use spaces. + +```java +public static Patch diff(List original, List revised, + BiPredicate equalizer) throws DiffException { + if (equalizer != null) { + return DiffUtils.diff(original, revised, + new MyersDiff<>(equalizer)); + } + return DiffUtils.diff(original, revised, new MyersDiff<>()); +} +``` + +This is a valid piece of source code: +* blocks without braces are not allowed +* after control statements (if, while, for) a whitespace is expected +* the opening brace should be in the same line as the control statement + ### To Install ### **This jar is not yet to get at maven central.** diff --git a/java-diff-utils.iml b/java-diff-utils.iml index 5f6b53a..1dc1f4d 100644 --- a/java-diff-utils.iml +++ b/java-diff-utils.iml @@ -1,29 +1,29 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nb-configuration.xml b/nb-configuration.xml index f169263..f5e3165 100644 --- a/nb-configuration.xml +++ b/nb-configuration.xml @@ -1,22 +1,22 @@ - - - - none - false - true - LF - false - + + + + none + false + true + LF + false + diff --git a/pom.xml b/pom.xml index 2c86f6a..c15a9a9 100644 --- a/pom.xml +++ b/pom.xml @@ -1,213 +1,272 @@ - 4.0.0 - com.github.java-diff-utils - diffutils - jar - 2.1-SNAPSHOT + 4.0.0 + com.github.java-diff-utils + diffutils + jar + 2.1-SNAPSHOT - java-diff-utils - The DiffUtils library for computing diffs, applying patches, generationg side-by-side view in Java. - https://github.com/wumpz/java-diff-utils - 2009 + java-diff-utils + The DiffUtils library for computing diffs, applying patches, generationg side-by-side view in Java. + https://github.com/wumpz/java-diff-utils + 2009 - - scm:git:https://github.com/wumpz/java-diff-utils.git - scm:git:ssh://git@github.com:wumpz/java-diff-utils.git - https://github.com/wumpz/java-diff-utils.git - diffutils-2.0 - + + scm:git:https://github.com/wumpz/java-diff-utils.git + scm:git:ssh://git@github.com:wumpz/java-diff-utils.git + https://github.com/wumpz/java-diff-utils.git + diffutils-2.0 + - - GitHub Issues - https://github.com/wumpz/java-diff-utils/issues - + + GitHub Issues + https://github.com/wumpz/java-diff-utils/issues + - - java-diff-utils - + + java-diff-utils + - - - Tobias Warneke - t.warneke@gmx.net - - - Dmitry Naumenko - dm.naumenko@gmail.com - - - Juanco Anez - juanco@suigeneris.org - - + + + Tobias Warneke + t.warneke@gmx.net + + + Dmitry Naumenko + dm.naumenko@gmail.com + + + Juanco Anez + juanco@suigeneris.org + + - - - The Apache Software License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - A business-friendly OSS license - - + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + A business-friendly OSS license + + - - UTF-8 - + + UTF-8 + - - - junit - junit - 4.12 - jar - test - - - org.eclipse.jgit - org.eclipse.jgit - 4.4.1.201607150455-r - - - com.googlecode.javaewah - JavaEWAH - - - commons-codec - commons-codec - - - commons-logging - commons-logging - - - org.apache.httpcomponents - httpclient - - - com.jcraft - jsch - - - org.slf4j - slf4j-api - - - - + + + junit + junit + 4.12 + jar + test + + + org.eclipse.jgit + org.eclipse.jgit + 4.4.1.201607150455-r + + + com.googlecode.javaewah + JavaEWAH + + + commons-codec + commons-codec + + + commons-logging + commons-logging + + + org.apache.httpcomponents + httpclient + + + com.jcraft + jsch + + + org.slf4j + slf4j-api + + + + - - + + - - org.apache.maven.plugins - maven-compiler-plugin - 3.6.1 - - 1.8 - 1.8 - UTF-8 - - + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + 1.8 + 1.8 + UTF-8 + + - - - - maven-jar-plugin - 3.0.2 - - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - - - - org.apache.felix - maven-bundle-plugin - 3.3.0 - - - bundle-manifest - process-classes - - manifest - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.10.4 - - ${javadoc.opts} - - - - attach-javadocs - - jar - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.19.1 - - - **/LR*.java - - - - - org.apache.maven.plugins - maven-release-plugin - 2.5.3 - - true - false - forked-path + + + + maven-jar-plugin + 3.0.2 + + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + + + + org.apache.felix + maven-bundle-plugin + 3.3.0 + + + bundle-manifest + process-classes + + manifest + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.4 + + ${javadoc.opts} + + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.19.1 + + + **/LR*.java + + + + + org.apache.maven.plugins + maven-release-plugin + 2.5.3 + + true + false + forked-path install - - - - - - - doclint-java8-disable - - [1.8,) - - - -Xdoclint:none - - - - long-running-tests - - - - org.apache.maven.plugins - maven-surefire-plugin - - - xxx - - - - - - - + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.17 + + + verify-style + process-classes + + check + + + + + true + true + ${project.build.sourceDirectory} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + com.puppycrawl.tools + checkstyle + 6.19 + + + + + + + + doclint-java8-disable + + [1.8,) + + + -Xdoclint:none + + + + long-running-tests + + + + org.apache.maven.plugins + maven-surefire-plugin + + + xxx + + + + + + + diff --git a/src/main/java/com/github/difflib/DiffUtils.java b/src/main/java/com/github/difflib/DiffUtils.java index c0a7a74..807d7b4 100644 --- a/src/main/java/com/github/difflib/DiffUtils.java +++ b/src/main/java/com/github/difflib/DiffUtils.java @@ -42,18 +42,16 @@ import static java.util.stream.Collectors.joining; public final class DiffUtils { /** - * Computes the difference between the original and revised list of elements with default diff - * algorithm + * Computes the difference between the original and revised list of elements with default diff algorithm * * @param original The original text. Must not be {@code null}. * @param revised The revised text. Must not be {@code null}. - * @return The patch describing the difference between the original and revised sequences. Never - * {@code null}. + * @return The patch describing the difference between the original and revised sequences. Never {@code null}. */ public static Patch diff(List original, List revised) throws DiffException { return DiffUtils.diff(original, revised, new MyersDiff<>()); } - + /** * Computes the difference between the original and revised text. */ @@ -62,19 +60,17 @@ public final class DiffUtils { } /** - * Computes the difference between the original and revised list of elements with default diff - * algorithm + * Computes the difference between the original and revised list of elements with default diff algorithm * * @param original The original text. Must not be {@code null}. * @param revised The revised text. Must not be {@code null}. * - * @param equalizer the equalizer object to replace the default compare algorithm - * (Object.equals). If {@code null} the default equalizer of the default algorithm is used.. - * @return The patch describing the difference between the original and revised sequences. Never - * {@code null}. + * @param equalizer the equalizer object to replace the default compare algorithm (Object.equals). If {@code null} + * the default equalizer of the default algorithm is used.. + * @return The patch describing the difference between the original and revised sequences. Never {@code null}. */ public static Patch diff(List original, List revised, - BiPredicate equalizer) throws DiffException { + BiPredicate equalizer) throws DiffException { if (equalizer != null) { return DiffUtils.diff(original, revised, new MyersDiff<>(equalizer)); @@ -83,28 +79,25 @@ public final class DiffUtils { } /** - * Computes the difference between the original and revised list of elements with default diff - * algorithm + * Computes the difference between the original and revised list of elements with default diff algorithm * * @param original The original text. Must not be {@code null}. * @param revised The revised text. Must not be {@code null}. * @param algorithm The diff algorithm. Must not be {@code null}. - * @return The patch describing the difference between the original and revised sequences. Never - * {@code null}. + * @return The patch describing the difference between the original and revised sequences. Never {@code null}. */ public static Patch diff(List original, List revised, DiffAlgorithm algorithm) throws DiffException { - Objects.requireNonNull(original,"original must not be null"); - Objects.requireNonNull(revised,"revised must not be null"); - Objects.requireNonNull(algorithm,"algorithm must not be null"); - + Objects.requireNonNull(original, "original must not be null"); + Objects.requireNonNull(revised, "revised must not be null"); + Objects.requireNonNull(algorithm, "algorithm must not be null"); + return Patch.generate(original, revised, algorithm.diff(original, revised)); } /** - * Computes the difference between the given texts inline. This one uses the "trick" to make out - * of texts lists of characters, like DiffRowGenerator does and merges those changes at the end - * together again. + * Computes the difference between the given texts inline. This one uses the "trick" to make out of texts lists of + * characters, like DiffRowGenerator does and merges those changes at the end together again. * * @param original * @param revised diff --git a/src/main/java/com/github/difflib/UnifiedDiffUtils.java b/src/main/java/com/github/difflib/UnifiedDiffUtils.java index c48b050..1395c79 100644 --- a/src/main/java/com/github/difflib/UnifiedDiffUtils.java +++ b/src/main/java/com/github/difflib/UnifiedDiffUtils.java @@ -29,6 +29,7 @@ import java.util.regex.Pattern; * @author toben */ public final class UnifiedDiffUtils { + private static final Pattern UNIFIED_DIFF_CHUNK_REGEXP = Pattern .compile("^@@\\s+-(?:(\\d+)(?:,(\\d+))?)\\s+\\+(?:(\\d+)(?:,(\\d+))?)\\s+@@$"); @@ -124,10 +125,10 @@ public final class UnifiedDiffUtils { return patch; } - + /** - * generateUnifiedDiff takes a Patch and some other arguments, returning the Unified Diff format - * text representing the Patch. + * generateUnifiedDiff takes a Patch and some other arguments, returning the Unified Diff format text representing + * the Patch. * * @param original - Filename of the original (unrevised file) * @param revised - Filename of the revised file @@ -195,10 +196,9 @@ public final class UnifiedDiffUtils { } return new ArrayList<>(); } - + /** - * processDeltas takes a list of Deltas and outputs them together in a single block of - * Unified-Diff-format text. + * processDeltas takes a list of Deltas and outputs them together in a single block of Unified-Diff-format text. * * @param origLines - the lines of the original file * @param deltas - the Deltas to be output as a single block @@ -289,7 +289,7 @@ public final class UnifiedDiffUtils { return buffer; } - + /** * getDeltaText returns the lines to be added to the Unified Diff text from the Delta parameter * @@ -307,7 +307,7 @@ public final class UnifiedDiffUtils { } return buffer; } - + private UnifiedDiffUtils() { } } diff --git a/src/main/java/com/github/difflib/algorithm/Change.java b/src/main/java/com/github/difflib/algorithm/Change.java index eb21d3f..b90e202 100644 --- a/src/main/java/com/github/difflib/algorithm/Change.java +++ b/src/main/java/com/github/difflib/algorithm/Change.java @@ -22,6 +22,7 @@ import com.github.difflib.patch.DeltaType; * @author toben */ public class Change { + public final DeltaType deltaType; public final int startOriginal; public final int endOriginal; diff --git a/src/main/java/com/github/difflib/algorithm/DiffAlgorithm.java b/src/main/java/com/github/difflib/algorithm/DiffAlgorithm.java index e6a2015..b97a15a 100644 --- a/src/main/java/com/github/difflib/algorithm/DiffAlgorithm.java +++ b/src/main/java/com/github/difflib/algorithm/DiffAlgorithm.java @@ -31,8 +31,8 @@ import java.util.*; public interface DiffAlgorithm { /** - * Computes the difference between the original sequence and the revised sequence and returns it - * as a {@link Patch} object. + * Computes the difference between the original sequence and the revised sequence and returns it as a {@link Patch} + * object. * * @param original The original sequence. Must not be {@code null}. * @param revised The revised sequence. Must not be {@code null}. @@ -43,8 +43,8 @@ public interface DiffAlgorithm { } /** - * Computes the difference between the original sequence and the revised sequence and returns it - * as a {@link Patch} object. + * Computes the difference between the original sequence and the revised sequence and returns it as a {@link Patch} + * object. * * @param original The original sequence. Must not be {@code null}. * @param revised The revised sequence. Must not be {@code null}. diff --git a/src/main/java/com/github/difflib/algorithm/DifferentiationFailedException.java b/src/main/java/com/github/difflib/algorithm/DifferentiationFailedException.java index 132288f..80c881e 100644 --- a/src/main/java/com/github/difflib/algorithm/DifferentiationFailedException.java +++ b/src/main/java/com/github/difflib/algorithm/DifferentiationFailedException.java @@ -19,12 +19,9 @@ limitations under the License. */ package com.github.difflib.algorithm; -import com.github.difflib.algorithm.DiffException; - /** - * Thrown whenever the differencing engine cannot produce the differences between two revisions of - * ta text. - + * Thrown whenever the differencing engine cannot produce the differences between two revisions of ta text. + * * @see MyersDiff * @see difflib.DiffAlgorithm */ diff --git a/src/main/java/com/github/difflib/algorithm/jgit/HistogramDiff.java b/src/main/java/com/github/difflib/algorithm/jgit/HistogramDiff.java index 978f56e..6ca8010 100644 --- a/src/main/java/com/github/difflib/algorithm/jgit/HistogramDiff.java +++ b/src/main/java/com/github/difflib/algorithm/jgit/HistogramDiff.java @@ -28,9 +28,8 @@ import org.eclipse.jgit.diff.Sequence; import org.eclipse.jgit.diff.SequenceComparator; /** - * HistorgramDiff using JGit - Library. This one is much more performant than the - * orginal Myers implementation. - * + * HistorgramDiff using JGit - Library. This one is much more performant than the orginal Myers implementation. + * * @author toben */ public class HistogramDiff implements DiffAlgorithm { @@ -43,19 +42,19 @@ public class HistogramDiff implements DiffAlgorithm { diffList.addAll(new org.eclipse.jgit.diff.HistogramDiff().diff(new DataListComparator<>(), new DataList<>(original), new DataList<>(revised))); List patch = new ArrayList<>(); for (Edit edit : diffList) { - DeltaType type = DeltaType.EQUAL; + DeltaType type = DeltaType.EQUAL; switch (edit.getType()) { case DELETE: - type = DeltaType.DELETE; + type = DeltaType.DELETE; break; case INSERT: - type = DeltaType.INSERT; + type = DeltaType.INSERT; break; case REPLACE: - type = DeltaType.CHANGE; + type = DeltaType.CHANGE; break; } - patch.add(new Change(type,edit.getBeginA(), edit.getEndA(), edit.getBeginB(), edit.getEndB())); + patch.add(new Change(type, edit.getBeginA(), edit.getEndA(), edit.getBeginB(), edit.getEndB())); } return patch; } diff --git a/src/main/java/com/github/difflib/algorithm/myers/MyersDiff.java b/src/main/java/com/github/difflib/algorithm/myers/MyersDiff.java index 6907f68..ec76ec3 100644 --- a/src/main/java/com/github/difflib/algorithm/myers/MyersDiff.java +++ b/src/main/java/com/github/difflib/algorithm/myers/MyersDiff.java @@ -20,9 +20,9 @@ limitations under the License. package com.github.difflib.algorithm.myers; import com.github.difflib.algorithm.Change; -import com.github.difflib.algorithm.DifferentiationFailedException; import com.github.difflib.algorithm.DiffAlgorithm; import com.github.difflib.algorithm.DiffException; +import com.github.difflib.algorithm.DifferentiationFailedException; import com.github.difflib.patch.DeltaType; import com.github.difflib.patch.Patch; import java.util.ArrayList; @@ -35,16 +35,14 @@ import java.util.function.BiPredicate; */ public final class MyersDiff implements DiffAlgorithm { - private final BiPredicate DEFAULT_EQUALIZER = Object::equals; - private final BiPredicate equalizer; - + private final BiPredicate DEFAULT_EQUALIZER = Object::equals; + private final BiPredicate equalizer; public MyersDiff() { equalizer = DEFAULT_EQUALIZER; } - - public MyersDiff(final BiPredicate equalizer) { + public MyersDiff(final BiPredicate equalizer) { Objects.requireNonNull(equalizer, "equalizer must not be null"); this.equalizer = equalizer; } @@ -64,9 +62,8 @@ public final class MyersDiff implements DiffAlgorithm { } /** - * Computes the minimum diffpath that expresses de differences between the - * original and revised sequences, according to Gene Myers differencing - * algorithm. + * Computes the minimum diffpath that expresses de differences between the original and revised sequences, according + * to Gene Myers differencing algorithm. * * @param orig The original sequence. * @param rev The revised sequence. @@ -138,8 +135,7 @@ public final class MyersDiff implements DiffAlgorithm { * @param orig The original sequence. * @param rev The revised sequence. * @return A {@link Patch} script corresponding to the path. - * @throws DifferentiationFailedException if a {@link Patch} could not be - * built from the given path. + * @throws DifferentiationFailedException if a {@link Patch} could not be built from the given path. */ private List buildRevision(PathNode actualPath, List orig, List rev) { Objects.requireNonNull(actualPath, "path is null"); diff --git a/src/main/java/com/github/difflib/algorithm/myers/PathNode.java b/src/main/java/com/github/difflib/algorithm/myers/PathNode.java index c60b482..01d669f 100644 --- a/src/main/java/com/github/difflib/algorithm/myers/PathNode.java +++ b/src/main/java/com/github/difflib/algorithm/myers/PathNode.java @@ -44,7 +44,7 @@ public final class PathNode { public final PathNode prev; public final boolean snake; - + public final boolean bootstrap; /** @@ -61,7 +61,7 @@ public final class PathNode { if (snake) { this.prev = prev; } else { - this.prev = (prev == null ? null : prev.previousSnake()); + this.prev = prev == null ? null : prev.previousSnake(); } this.snake = snake; } @@ -82,11 +82,10 @@ public final class PathNode { } /** - * Skips sequences of {@link DiffNode DiffNodes} until a {@link Snake} or bootstrap node is - * found, or the end of the path is reached. + * Skips sequences of {@link DiffNode DiffNodes} until a {@link 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 null if - * none found. + * @return The next first {@link Snake} or bootstrap node in the path, or null if none found. */ public final PathNode previousSnake() { if (isBootstrap()) { diff --git a/src/main/java/com/github/difflib/patch/Chunk.java b/src/main/java/com/github/difflib/patch/Chunk.java index 8b21e7b..5855c3f 100644 --- a/src/main/java/com/github/difflib/patch/Chunk.java +++ b/src/main/java/com/github/difflib/patch/Chunk.java @@ -26,10 +26,9 @@ import java.util.List; * Holds the information about the part of text involved in the diff process * *

- * Text is represented as Object[] because the diff engine is capable of handling more - * than plain ascci. In fact, arrays or lists of any type that implements - * {@link java.lang.Object#hashCode hashCode()} and {@link java.lang.Object#equals equals()} - * correctly can be subject to differencing using this library. + * Text is represented as Object[] because the diff engine is capable of handling more than plain ascci. In + * fact, arrays or lists of any type that implements {@link java.lang.Object#hashCode hashCode()} and + * {@link java.lang.Object#equals equals()} correctly can be subject to differencing using this library. *

* * @author extends Delta { target.add(position + i, lines.get(i)); } } - + @Override public void restore(List target) { int position = getRevised().getPosition(); diff --git a/src/main/java/com/github/difflib/patch/Patch.java b/src/main/java/com/github/difflib/patch/Patch.java index 4d2f2e4..ec7c357 100644 --- a/src/main/java/com/github/difflib/patch/Patch.java +++ b/src/main/java/com/github/difflib/patch/Patch.java @@ -41,11 +41,11 @@ public final class Patch { public Patch() { this(10); } - + public Patch(int estimatedPatchSize) { - deltas = new ArrayList<>(estimatedPatchSize); + deltas = new ArrayList<>(estimatedPatchSize); } - + /** * Apply this patch to the given target * @@ -87,7 +87,7 @@ public final class Patch { deltas.add(delta); } - /** + /** * Get the list of computed deltas * * @return the deltas @@ -101,7 +101,7 @@ public final class Patch { public String toString() { return "Patch{" + "deltas=" + deltas + '}'; } - + public static Patch generate(List original, List revised, List changes) { Patch patch = new Patch<>(changes.size()); for (Change change : changes) { diff --git a/src/main/java/com/github/difflib/text/DiffRow.java b/src/main/java/com/github/difflib/text/DiffRow.java index f6ab5f5..dd8cd9d 100644 --- a/src/main/java/com/github/difflib/text/DiffRow.java +++ b/src/main/java/com/github/difflib/text/DiffRow.java @@ -22,8 +22,7 @@ package com.github.difflib.text; import java.io.Serializable; /** - * Describes the diff row in form [tag, oldLine, newLine) for showing the difference between two - * texts + * Describes the diff row in form [tag, oldLine, newLine) for showing the difference between two texts * * @author Dmitry Naumenko */ diff --git a/src/main/java/com/github/difflib/text/DiffRowGenerator.java b/src/main/java/com/github/difflib/text/DiffRowGenerator.java index e25e928..ad13542 100644 --- a/src/main/java/com/github/difflib/text/DiffRowGenerator.java +++ b/src/main/java/com/github/difflib/text/DiffRowGenerator.java @@ -43,7 +43,7 @@ import java.util.regex.Pattern; * * For instantiating the DiffRowGenerator you should use the its builder. Like in example * DiffRowGenerator generator = new DiffRowGenerator.Builder().showInlineDiffs(true). - * ignoreWhiteSpaces(true).columnWidth(100).build(); + * ignoreWhiteSpaces(true).columnWidth(100).build(); * */ public class DiffRowGenerator { diff --git a/src/test/java/com/github/difflib/DiffUtilsTest.java b/src/test/java/com/github/difflib/DiffUtilsTest.java index d8aa3cf..d815401 100644 --- a/src/test/java/com/github/difflib/DiffUtilsTest.java +++ b/src/test/java/com/github/difflib/DiffUtilsTest.java @@ -1,6 +1,5 @@ package com.github.difflib; -import com.github.difflib.DiffUtils; import com.github.difflib.algorithm.DiffException; import com.github.difflib.patch.ChangeDelta; import com.github.difflib.patch.Chunk; @@ -138,25 +137,25 @@ public class DiffUtilsTest { @Ignore public void testPossibleDiffHangOnLargeDatasetDnaumenkoIssue26() throws IOException, DiffException { ZipFile zip = new ZipFile(TestConstants.MOCK_FOLDER + "/large_dataset1.zip"); - + Patch patch = DiffUtils.diff( - readStringListFromInputStream(zip.getInputStream(zip.getEntry("ta"))), + readStringListFromInputStream(zip.getInputStream(zip.getEntry("ta"))), readStringListFromInputStream(zip.getInputStream(zip.getEntry("tb")))); - + assertEquals(1, patch.getDeltas().size()); } - + public static List readStringListFromInputStream(InputStream is) throws IOException { try (BufferedReader reader = new BufferedReader( new InputStreamReader(is, Charset.forName(StandardCharsets.UTF_8.name())))) { - + return reader.lines().collect(toList()); } } - + @Test public void testDiffMyersExample1() throws DiffException { - final Patch patch = DiffUtils.diff(Arrays.asList("A","B","C","A","B","B","A"), Arrays.asList("C","B","A","B","A","C")); + final Patch patch = DiffUtils.diff(Arrays.asList("A", "B", "C", "A", "B", "B", "A"), Arrays.asList("C", "B", "A", "B", "A", "C")); assertNotNull(patch); assertEquals(4, patch.getDeltas().size()); assertEquals("Patch{deltas=[[DeleteDelta, position: 0, lines: [A, B]], [InsertDelta, position: 3, lines: [B]], [DeleteDelta, position: 5, lines: [B]], [InsertDelta, position: 7, lines: [C]]]}", patch.toString()); diff --git a/src/test/java/com/github/difflib/GenerateUnifiedDiffTest.java b/src/test/java/com/github/difflib/GenerateUnifiedDiffTest.java index 79ceec3..89ab32f 100644 --- a/src/test/java/com/github/difflib/GenerateUnifiedDiffTest.java +++ b/src/test/java/com/github/difflib/GenerateUnifiedDiffTest.java @@ -1,7 +1,5 @@ package com.github.difflib; -import com.github.difflib.DiffUtils; -import com.github.difflib.UnifiedDiffUtils; import com.github.difflib.algorithm.DiffException; import com.github.difflib.patch.Patch; import com.github.difflib.patch.PatchFailedException; diff --git a/src/test/java/com/github/difflib/TestConstants.java b/src/test/java/com/github/difflib/TestConstants.java index 7abb9a4..56f5bf6 100644 --- a/src/test/java/com/github/difflib/TestConstants.java +++ b/src/test/java/com/github/difflib/TestConstants.java @@ -7,6 +7,7 @@ package com.github.difflib; * */ 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}. diff --git a/src/test/java/com/github/difflib/algorithm/jgit/HistogramDiffTest.java b/src/test/java/com/github/difflib/algorithm/jgit/HistogramDiffTest.java index 1de6588..ec44ade 100644 --- a/src/test/java/com/github/difflib/algorithm/jgit/HistogramDiffTest.java +++ b/src/test/java/com/github/difflib/algorithm/jgit/HistogramDiffTest.java @@ -15,44 +15,39 @@ */ package com.github.difflib.algorithm.jgit; -import com.github.difflib.algorithm.jgit.HistogramDiff; -import static com.github.difflib.DiffUtilsTest.readStringListFromInputStream; -import com.github.difflib.TestConstants; import com.github.difflib.algorithm.DiffException; import com.github.difflib.patch.Patch; import com.github.difflib.patch.PatchFailedException; -import java.io.IOException; import java.util.Arrays; import java.util.List; -import java.util.zip.ZipFile; import org.junit.After; import org.junit.AfterClass; +import static org.junit.Assert.*; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import static org.junit.Assert.*; /** * * @author toben */ public class HistogramDiffTest { - + public HistogramDiffTest() { } - + @BeforeClass public static void setUpClass() { } - + @AfterClass public static void tearDownClass() { } - + @Before public void setUp() { } - + @After public void tearDown() { } @@ -62,14 +57,14 @@ public class HistogramDiffTest { */ @Test public void testDiff() throws DiffException, PatchFailedException { - List orgList = Arrays.asList("A","B","C","A","B","B","A"); - List revList = Arrays.asList("C","B","A","B","A","C"); + List orgList = Arrays.asList("A", "B", "C", "A", "B", "B", "A"); + List revList = Arrays.asList("C", "B", "A", "B", "A", "C"); final Patch patch = Patch.generate(orgList, revList, new HistogramDiff().diff(orgList, revList)); System.out.println(patch); assertNotNull(patch); assertEquals(3, patch.getDeltas().size()); assertEquals("Patch{deltas=[[DeleteDelta, position: 0, lines: [A, B]], [DeleteDelta, position: 3, lines: [A, B]], [InsertDelta, position: 7, lines: [B, A, C]]]}", patch.toString()); - + List patched = patch.applyTo(orgList); assertEquals(revList, patched); } diff --git a/src/test/java/com/github/difflib/algorithm/jgit/LRHistogramDiffTest.java b/src/test/java/com/github/difflib/algorithm/jgit/LRHistogramDiffTest.java index 6ddb26d..93e2950 100644 --- a/src/test/java/com/github/difflib/algorithm/jgit/LRHistogramDiffTest.java +++ b/src/test/java/com/github/difflib/algorithm/jgit/LRHistogramDiffTest.java @@ -15,61 +15,58 @@ */ package com.github.difflib.algorithm.jgit; -import com.github.difflib.algorithm.jgit.HistogramDiff; import static com.github.difflib.DiffUtilsTest.readStringListFromInputStream; import com.github.difflib.TestConstants; import com.github.difflib.algorithm.DiffException; import com.github.difflib.patch.Patch; import com.github.difflib.patch.PatchFailedException; import java.io.IOException; -import java.util.Arrays; import java.util.List; import java.util.zip.ZipFile; import org.junit.After; import org.junit.AfterClass; +import static org.junit.Assert.*; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import static org.junit.Assert.*; /** * * @author toben */ public class LRHistogramDiffTest { - + public LRHistogramDiffTest() { } - + @BeforeClass public static void setUpClass() { } - + @AfterClass public static void tearDownClass() { } - + @Before public void setUp() { } - + @After public void tearDown() { } - @Test public void testPossibleDiffHangOnLargeDatasetDnaumenkoIssue26() throws IOException, DiffException, PatchFailedException { ZipFile zip = new ZipFile(TestConstants.MOCK_FOLDER + "/large_dataset1.zip"); List original = readStringListFromInputStream(zip.getInputStream(zip.getEntry("ta"))); List revised = readStringListFromInputStream(zip.getInputStream(zip.getEntry("tb"))); - + Patch patch = Patch.generate(original, revised, new HistogramDiff().diff(original, revised)); - + assertEquals(34, patch.getDeltas().size()); - + List created = patch.applyTo(original); assertArrayEquals(revised.toArray(), created.toArray()); } - + } diff --git a/src/test/java/com/github/difflib/algorithm/myers/MyersDiffTest.java b/src/test/java/com/github/difflib/algorithm/myers/MyersDiffTest.java index 6ef04e6..9b911ff 100644 --- a/src/test/java/com/github/difflib/algorithm/myers/MyersDiffTest.java +++ b/src/test/java/com/github/difflib/algorithm/myers/MyersDiffTest.java @@ -15,18 +15,12 @@ */ package com.github.difflib.algorithm.myers; -import com.github.difflib.algorithm.myers.MyersDiff; -import com.github.difflib.DiffUtils; import com.github.difflib.algorithm.DiffException; import com.github.difflib.patch.Patch; import java.util.Arrays; import java.util.List; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; import static org.junit.Assert.*; +import org.junit.Test; /** * diff --git a/src/test/java/com/github/difflib/patch/PatchTest.java b/src/test/java/com/github/difflib/patch/PatchTest.java index cfda69a..792785e 100644 --- a/src/test/java/com/github/difflib/patch/PatchTest.java +++ b/src/test/java/com/github/difflib/patch/PatchTest.java @@ -1,7 +1,5 @@ package com.github.difflib.patch; -import com.github.difflib.patch.Patch; -import com.github.difflib.patch.PatchFailedException; import com.github.difflib.DiffUtils; import com.github.difflib.algorithm.DiffException; import java.util.Arrays; diff --git a/src/test/java/com/github/difflib/text/DiffRowGeneratorTest.java b/src/test/java/com/github/difflib/text/DiffRowGeneratorTest.java index 616c189..3326fe9 100644 --- a/src/test/java/com/github/difflib/text/DiffRowGeneratorTest.java +++ b/src/test/java/com/github/difflib/text/DiffRowGeneratorTest.java @@ -1,7 +1,5 @@ package com.github.difflib.text; -import com.github.difflib.text.DiffRow; -import com.github.difflib.text.DiffRowGenerator; import com.github.difflib.algorithm.DiffException; import java.util.Arrays; import java.util.List; @@ -24,7 +22,7 @@ public class DiffRowGeneratorTest { assertEquals(3, rows.size()); } - + @Test public void testGenerator_Default2() throws DiffException { String first = "anything \n \nother"; @@ -83,14 +81,14 @@ public class DiffRowGeneratorTest { System.out.println(row); } } - + @Test public void testGeneratorWithWordWrap() throws DiffException { String first = "anything \n \nother"; String second = "anything\n\nother"; DiffRowGenerator generator = DiffRowGenerator.create() - .columnWidth(5) + .columnWidth(5) .build(); List rows = generator.generateDiffRows(split(first), split(second)); print(rows); @@ -100,7 +98,7 @@ public class DiffRowGeneratorTest { assertEquals("[CHANGE, ,]", rows.get(1).toString()); assertEquals("[EQUAL,other,other]", rows.get(2).toString()); } - + @Test public void testGeneratorWithMerge() throws DiffException { String first = "anything \n \nother"; @@ -118,20 +116,20 @@ public class DiffRowGeneratorTest { assertEquals("[CHANGE, ,]", rows.get(1).toString()); assertEquals("[EQUAL,other,other]", rows.get(2).toString()); } - + @Test public void testGeneratorWithMerge2() throws DiffException { DiffRowGenerator generator = DiffRowGenerator.create() .showInlineDiffs(true) .mergeOriginalRevised(true) .build(); - List rows = generator.generateDiffRows(Arrays.asList("Test"),Arrays.asList("ester")); + List rows = generator.generateDiffRows(Arrays.asList("Test"), Arrays.asList("ester")); print(rows); assertEquals(1, rows.size()); assertEquals("[CHANGE,Tester,ester]", rows.get(0).toString()); } - + @Test public void testGeneratorWithMerge3() throws DiffException { String first = "test\nanything \n \nother"; @@ -152,7 +150,7 @@ public class DiffRowGeneratorTest { assertEquals("[INSERT,test,test]", rows.get(4).toString()); assertEquals("[INSERT,test2,test2]", rows.get(5).toString()); } - + @Test public void testGeneratorWithMergeByWord4() throws DiffException { DiffRowGenerator generator = DiffRowGenerator.create() @@ -160,13 +158,13 @@ public class DiffRowGeneratorTest { .mergeOriginalRevised(true) .inlineDiffByWord(true) .build(); - List rows = generator.generateDiffRows(Arrays.asList("Test"),Arrays.asList("ester")); + List rows = generator.generateDiffRows(Arrays.asList("Test"), Arrays.asList("ester")); print(rows); assertEquals(1, rows.size()); assertEquals("[CHANGE,Testester,ester]", rows.get(0).toString()); } - + @Test public void testGeneratorWithMergeByWord5() throws DiffException { DiffRowGenerator generator = DiffRowGenerator.create() @@ -175,20 +173,20 @@ public class DiffRowGeneratorTest { .inlineDiffByWord(true) .columnWidth(80) .build(); - List rows = generator.generateDiffRows(Arrays.asList("Test feature"),Arrays.asList("ester feature best")); + List rows = generator.generateDiffRows(Arrays.asList("Test feature"), Arrays.asList("ester feature best")); print(rows); assertEquals(1, rows.size()); assertEquals("[CHANGE,Testester
feature best,ester feature best]", rows.get(0).toString()); } - + @Test public void testSplitString() { List list = DiffRowGenerator.splitStringPreserveDelimiter("test,test2"); assertEquals(3, list.size()); assertEquals("[test, ,, test2]", list.toString()); } - + @Test public void testSplitString2() { List list = DiffRowGenerator.splitStringPreserveDelimiter("test , test2"); @@ -196,7 +194,7 @@ public class DiffRowGeneratorTest { assertEquals(5, list.size()); assertEquals("[test, , ,, , test2]", list.toString()); } - + @Test public void testSplitString3() { List list = DiffRowGenerator.splitStringPreserveDelimiter("test,test2,"); @@ -204,8 +202,7 @@ public class DiffRowGeneratorTest { assertEquals(4, list.size()); assertEquals("[test, ,, test2, ,]", list.toString()); } - - + @Test public void testGeneratorExample1() throws DiffException { DiffRowGenerator generator = DiffRowGenerator.create() @@ -218,13 +215,13 @@ public class DiffRowGeneratorTest { List rows = generator.generateDiffRows( Arrays.asList("This is a test senctence."), Arrays.asList("This is a test for diffutils.")); - - System.out.println(rows.get(0).getOldLine()); - + + System.out.println(rows.get(0).getOldLine()); + assertEquals(1, rows.size()); assertEquals("This is a test ~senctence~**for diffutils**.", rows.get(0).getOldLine()); } - + @Test public void testGeneratorExample2() throws DiffException { DiffRowGenerator generator = DiffRowGenerator.create() @@ -236,25 +233,25 @@ public class DiffRowGeneratorTest { List rows = generator.generateDiffRows( Arrays.asList("This is a test senctence.", "This is the second line.", "And here is the finish."), Arrays.asList("This is a test for diffutils.", "This is the second line.")); - + System.out.println("|original|new|"); System.out.println("|--------|---|"); for (DiffRow row : rows) { System.out.println("|" + row.getOldLine() + "|" + row.getNewLine() + "|"); } - + assertEquals(3, rows.size()); assertEquals("This is a test ~senctence~.", rows.get(0).getOldLine()); assertEquals("This is a test **for diffutils**.", rows.get(0).getNewLine()); } - + @Test public void testGeneratorUnchanged() throws DiffException { String first = "anything \n \nother"; String second = "anything\n\nother"; DiffRowGenerator generator = DiffRowGenerator.create() - .columnWidth(5) + .columnWidth(5) .reportLinesUnchanged(true) .build(); List rows = generator.generateDiffRows(split(first), split(second)); diff --git a/src/test/java/com/github/difflib/text/StringUtilsTest.java b/src/test/java/com/github/difflib/text/StringUtilsTest.java index ad8f1db..2b120d0 100644 --- a/src/test/java/com/github/difflib/text/StringUtilsTest.java +++ b/src/test/java/com/github/difflib/text/StringUtilsTest.java @@ -16,8 +16,8 @@ package com.github.difflib.text; import java.util.Collections; -import org.junit.Test; import static org.junit.Assert.*; +import org.junit.Test; /** * @@ -38,7 +38,7 @@ public class StringUtilsTest { */ @Test public void testNormalize_String() { - assertEquals(" test",StringUtils.normalize("\ttest")); + assertEquals(" test", StringUtils.normalize("\ttest")); } /** @@ -46,7 +46,7 @@ public class StringUtilsTest { */ @Test public void testNormalize_List() { - assertEquals(Collections.singletonList(" test"),StringUtils.normalize(Collections.singletonList("\ttest"))); + assertEquals(Collections.singletonList(" test"), StringUtils.normalize(Collections.singletonList("\ttest"))); } /** @@ -58,10 +58,10 @@ public class StringUtilsTest { assertEquals("tes
t", StringUtils.wrapText("test", 3)); assertEquals("test", StringUtils.wrapText("test", 10)); } - + @Test(expected = IllegalArgumentException.class) public void testWrapText_String_int_zero() { assertEquals("test", StringUtils.wrapText("test", -1)); } - + }