13 Commits

Author SHA1 Message Date
wumpz
0a2053f71a [maven-release-plugin] prepare release diffutils-2.1 2017-11-09 22:38:40 +01:00
wumpz
4f6b1839f8 2017-11-09 22:24:46 +01:00
wumpz
5764356be2 2017-11-09 22:12:57 +01:00
wumpz
4f6f8dbcf2 fixes #14 2017-11-09 14:34:50 +01:00
wumpz
573460df9c preparing maven central release 2017-11-09 12:33:27 +01:00
wumpz
d2a432059d preparing maven central release 2017-11-09 12:30:47 +01:00
wumpz
90eaf2e134 starting corrections for maven central release 2017-11-08 08:29:59 +01:00
wumpz
e6fa5938a9 included checkstyle source code conventions 2017-10-25 08:49:20 +02:00
wumpz
88146c6afb make columnwith 0, meaning no text wrap, the standard 2017-09-28 13:25:54 +02:00
wumpz
aed1d31c2b 2017-08-30 13:46:55 +02:00
wumpz
5d5218ba30 fixes #11 2017-08-18 14:50:32 +02:00
wumpz
1107f43f36 fixes #11 2017-08-18 14:48:35 +02:00
wumpz
6c91ef68df [maven-release-plugin] prepare for next development iteration 2017-08-14 09:21:33 +02:00
31 changed files with 650 additions and 460 deletions

View File

@@ -50,6 +50,10 @@ 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. 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 ### ### Changelog ###
* Version 2.1-SNAPSHOT
* included checkstyle source code conventions
* groupid changed to **com.github.wumpz**, due to maven central releasing
* allow configurable splitting of lines to define the blocks to compare (words, characters, phrases).
* Version 2.0 * Version 2.0
* switch to maven and removed other artifacts * switch to maven and removed other artifacts
* changed groupid to **com.github.java-diff-utils** due to different forks at github * changed groupid to **com.github.java-diff-utils** due to different forks at github
@@ -66,6 +70,26 @@ But it can easily replaced by any other which is better for handing your texts.
* Ant build script * Ant build script
* Generate output in unified diff format (thanks for Bill James) * 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 <T> Patch<T> diff(List<T> original, List<T> revised,
BiPredicate<T, T> 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 ### ### To Install ###
**This jar is not yet to get at maven central.** **This jar is not yet to get at maven central.**
@@ -73,7 +97,7 @@ But it can easily replaced by any other which is better for handing your texts.
Just add the code below to your maven dependencies: Just add the code below to your maven dependencies:
``` ```
<dependency> <dependency>
<groupId>com.github.java-diff-utils</groupId> <groupId>com.github.wumpz</groupId>
<artifactId>diffutils</artifactId> <artifactId>diffutils</artifactId>
   <version>2.0-SNAPSHOT</version>    <version>2.0-SNAPSHOT</version>
</dependency> </dependency>

11
nbactions.xml Normal file
View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<actions>
<action>
<actionName>CUSTOM-clean deploy</actionName>
<displayName>clean deploy</displayName>
<goals>
<goal>clean</goal>
<goal>deploy</goal>
</goals>
</action>
</actions>

116
pom.xml
View File

@@ -1,27 +1,30 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.github.java-diff-utils</groupId> <groupId>com.github.wumpz</groupId>
<artifactId>diffutils</artifactId> <artifactId>diffutils</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>2.0</version> <version>2.1</version>
<name>java-diff-utils</name> <name>java-diff-utils</name>
<description>The DiffUtils library for computing diffs, applying patches, generationg side-by-side view in Java.</description> <description>The DiffUtils library for computing diffs, applying patches, generationg side-by-side view in Java.</description>
<url>https://github.com/wumpz/java-diff-utils</url> <url>https://github.com/wumpz/java-diff-utils</url>
<inceptionYear>2009</inceptionYear> <inceptionYear>2009</inceptionYear>
<!--
to make a local release <distributionManagement>
<parent> <repository>
<groupId>org.sonatype.oss</groupId> <id>sonatype-nexus-staging</id>
<artifactId>oss-parent</artifactId> <url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
<version>9</version> </repository>
</parent> <snapshotRepository>
--> <id>sonatype-nexus-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
<scm> <scm>
<connection>scm:git:https://github.com/wumpz/java-diff-utils.git</connection> <connection>scm:git:https://github.com/wumpz/java-diff-utils.git</connection>
<developerConnection>scm:git:ssh://git@github.com:wumpz/java-diff-utils.git</developerConnection> <developerConnection>scm:git:ssh://git@github.com:wumpz/java-diff-utils.git</developerConnection>
<url>https://github.com/wumpz/java-diff-utils.git</url> <url>https://github.com/wumpz/java-diff-utils.git</url>
<tag>diffutils-2.0</tag> <tag>diffutils-2.1</tag>
</scm> </scm>
<issueManagement> <issueManagement>
@@ -180,9 +183,98 @@
<goals>install</goals> <goals>install</goals>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<id>verify-style</id>
<phase>process-classes</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<logViolationsToConsole>true</logViolationsToConsole>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
<checkstyleRules>
<module name="Checker">
<module name="SuppressWarningsFilter" />
<module name="FileTabCharacter" />
<!-- git checkout may change linefeeds on the fly
<module name="RegexpMultiline">
<property name="format" value="(?s:(\r\n|\r).*)" />
<property name="message" value="CRLF and CR line endings are prohibited, but this file uses them." />
</module>
-->
<module name="TreeWalker">
<module name="AvoidNestedBlocks" />
<module name="ConstantName" />
<module name="EmptyCatchBlock" />
<module name="EmptyStatement" />
<module name="MissingOverride" />
<module name="MultipleVariableDeclarations" />
<module name="ParameterAssignment" />
<module name="StringLiteralEquality" />
<module name="RedundantImport" />
<module name="UnusedImports" />
<module name="WhitespaceAfter" />
<module name="NeedBraces" />
<module name="UnnecessaryParentheses" />
<module name="LeftCurly" />
<module name="RightCurly" />
<module name="SuppressWarningsHolder" />
</module>
</module>
</checkstyleRules>
</configuration>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>6.19</version>
</dependency>
</dependencies>
</plugin>
</plugins> </plugins>
</build> </build>
<profiles> <profiles>
<profile>
<id>sign-release-artifacts</id>
<activation>
<property>
<name>performRelease</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
<configuration>
<keyname>f22e0543</keyname>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile> <profile>
<id>doclint-java8-disable</id> <id>doclint-java8-disable</id>
<activation> <activation>

View File

@@ -25,9 +25,9 @@ import com.github.difflib.algorithm.myers.MyersDiff;
import com.github.difflib.patch.Delta; import com.github.difflib.patch.Delta;
import com.github.difflib.patch.Patch; import com.github.difflib.patch.Patch;
import com.github.difflib.patch.PatchFailedException; import com.github.difflib.patch.PatchFailedException;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.function.BiPredicate; import java.util.function.BiPredicate;
@@ -42,13 +42,11 @@ import static java.util.stream.Collectors.joining;
public final class DiffUtils { public final class DiffUtils {
/** /**
* Computes the difference between the original and revised list of elements with default diff * Computes the difference between the original and revised list of elements with default diff algorithm
* algorithm
* *
* @param original The original text. Must not be {@code null}. * @param original The original text. Must not be {@code null}.
* @param revised The revised 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 * @return The patch describing the difference between the original and revised sequences. Never {@code null}.
* {@code null}.
*/ */
public static <T> Patch<T> diff(List<T> original, List<T> revised) throws DiffException { public static <T> Patch<T> diff(List<T> original, List<T> revised) throws DiffException {
return DiffUtils.diff(original, revised, new MyersDiff<>()); return DiffUtils.diff(original, revised, new MyersDiff<>());
@@ -62,16 +60,14 @@ public final class DiffUtils {
} }
/** /**
* Computes the difference between the original and revised list of elements with default diff * Computes the difference between the original and revised list of elements with default diff algorithm
* algorithm
* *
* @param original The original text. Must not be {@code null}. * @param original The original text. Must not be {@code null}.
* @param revised The revised 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 * @param equalizer the equalizer object to replace the default compare algorithm (Object.equals). If {@code null}
* (Object.equals). If {@code null} the default equalizer of the default algorithm is used.. * the default equalizer of the default algorithm is used..
* @return The patch describing the difference between the original and revised sequences. Never * @return The patch describing the difference between the original and revised sequences. Never {@code null}.
* {@code null}.
*/ */
public static <T> Patch<T> diff(List<T> original, List<T> revised, public static <T> Patch<T> diff(List<T> original, List<T> revised,
BiPredicate<T, T> equalizer) throws DiffException { BiPredicate<T, T> equalizer) throws DiffException {
@@ -83,14 +79,12 @@ public final class DiffUtils {
} }
/** /**
* Computes the difference between the original and revised list of elements with default diff * Computes the difference between the original and revised list of elements with default diff algorithm
* algorithm
* *
* @param original The original text. Must not be {@code null}. * @param original The original text. Must not be {@code null}.
* @param revised The revised 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}. * @param algorithm The diff algorithm. Must not be {@code null}.
* @return The patch describing the difference between the original and revised sequences. Never * @return The patch describing the difference between the original and revised sequences. Never {@code null}.
* {@code null}.
*/ */
public static <T> Patch<T> diff(List<T> original, List<T> revised, public static <T> Patch<T> diff(List<T> original, List<T> revised,
DiffAlgorithm<T> algorithm) throws DiffException { DiffAlgorithm<T> algorithm) throws DiffException {
@@ -102,17 +96,16 @@ public final class DiffUtils {
} }
/** /**
* Computes the difference between the given texts inline. This one uses the "trick" to make out * Computes the difference between the given texts inline. This one uses the "trick" to make out of texts lists of
* of texts lists of characters, like DiffRowGenerator does and merges those changes at the end * characters, like DiffRowGenerator does and merges those changes at the end together again.
* together again.
* *
* @param original * @param original
* @param revised * @param revised
* @return * @return
*/ */
public static Patch<String> diffInline(String original, String revised) throws DiffException { public static Patch<String> diffInline(String original, String revised) throws DiffException {
LinkedList<String> origList = new LinkedList<>(); List<String> origList = new ArrayList<>();
LinkedList<String> revList = new LinkedList<>(); List<String> revList = new ArrayList<>();
for (Character character : original.toCharArray()) { for (Character character : original.toCharArray()) {
origList.add(character.toString()); origList.add(character.toString());
} }

View File

@@ -29,6 +29,7 @@ import java.util.regex.Pattern;
* @author toben * @author toben
*/ */
public final class UnifiedDiffUtils { public final class UnifiedDiffUtils {
private static final Pattern UNIFIED_DIFF_CHUNK_REGEXP = Pattern private static final Pattern UNIFIED_DIFF_CHUNK_REGEXP = Pattern
.compile("^@@\\s+-(?:(\\d+)(?:,(\\d+))?)\\s+\\+(?:(\\d+)(?:,(\\d+))?)\\s+@@$"); .compile("^@@\\s+-(?:(\\d+)(?:,(\\d+))?)\\s+\\+(?:(\\d+)(?:,(\\d+))?)\\s+@@$");
@@ -126,8 +127,8 @@ public final class UnifiedDiffUtils {
} }
/** /**
* generateUnifiedDiff takes a Patch and some other arguments, returning the Unified Diff format * generateUnifiedDiff takes a Patch and some other arguments, returning the Unified Diff format text representing
* text representing the Patch. * the Patch.
* *
* @param original - Filename of the original (unrevised file) * @param original - Filename of the original (unrevised file)
* @param revised - Filename of the revised file * @param revised - Filename of the revised file
@@ -197,8 +198,7 @@ public final class UnifiedDiffUtils {
} }
/** /**
* processDeltas takes a list of Deltas and outputs them together in a single block of * processDeltas takes a list of Deltas and outputs them together in a single block of Unified-Diff-format text.
* Unified-Diff-format text.
* *
* @param origLines - the lines of the original file * @param origLines - the lines of the original file
* @param deltas - the Deltas to be output as a single block * @param deltas - the Deltas to be output as a single block

View File

@@ -22,6 +22,7 @@ import com.github.difflib.patch.DeltaType;
* @author toben * @author toben
*/ */
public class Change { public class Change {
public final DeltaType deltaType; public final DeltaType deltaType;
public final int startOriginal; public final int startOriginal;
public final int endOriginal; public final int endOriginal;

View File

@@ -31,8 +31,8 @@ import java.util.*;
public interface DiffAlgorithm<T> { public interface DiffAlgorithm<T> {
/** /**
* Computes the difference between the original sequence and the revised sequence and returns it * Computes the difference between the original sequence and the revised sequence and returns it as a {@link Patch}
* as a {@link Patch} object. * object.
* *
* @param original The original sequence. Must not be {@code null}. * @param original The original sequence. Must not be {@code null}.
* @param revised The revised sequence. Must not be {@code null}. * @param revised The revised sequence. Must not be {@code null}.
@@ -43,8 +43,8 @@ public interface DiffAlgorithm<T> {
} }
/** /**
* Computes the difference between the original sequence and the revised sequence and returns it * Computes the difference between the original sequence and the revised sequence and returns it as a {@link Patch}
* as a {@link Patch} object. * object.
* *
* @param original The original sequence. Must not be {@code null}. * @param original The original sequence. Must not be {@code null}.
* @param revised The revised sequence. Must not be {@code null}. * @param revised The revised sequence. Must not be {@code null}.

View File

@@ -19,12 +19,9 @@ limitations under the License.
*/ */
package com.github.difflib.algorithm; package com.github.difflib.algorithm;
import com.github.difflib.algorithm.DiffException;
/** /**
* Thrown whenever the differencing engine cannot produce the differences between two revisions of * Thrown whenever the differencing engine cannot produce the differences between two revisions of ta text.
* ta text. *
* @see MyersDiff * @see MyersDiff
* @see difflib.DiffAlgorithm * @see difflib.DiffAlgorithm
*/ */

View File

@@ -28,8 +28,7 @@ import org.eclipse.jgit.diff.Sequence;
import org.eclipse.jgit.diff.SequenceComparator; import org.eclipse.jgit.diff.SequenceComparator;
/** /**
* HistorgramDiff using JGit - Library. This one is much more performant than the * HistorgramDiff using JGit - Library. This one is much more performant than the orginal Myers implementation.
* orginal Myers implementation.
* *
* @author toben * @author toben
*/ */

View File

@@ -20,9 +20,9 @@ limitations under the License.
package com.github.difflib.algorithm.myers; package com.github.difflib.algorithm.myers;
import com.github.difflib.algorithm.Change; import com.github.difflib.algorithm.Change;
import com.github.difflib.algorithm.DifferentiationFailedException;
import com.github.difflib.algorithm.DiffAlgorithm; import com.github.difflib.algorithm.DiffAlgorithm;
import com.github.difflib.algorithm.DiffException; import com.github.difflib.algorithm.DiffException;
import com.github.difflib.algorithm.DifferentiationFailedException;
import com.github.difflib.patch.DeltaType; import com.github.difflib.patch.DeltaType;
import com.github.difflib.patch.Patch; import com.github.difflib.patch.Patch;
import java.util.ArrayList; import java.util.ArrayList;
@@ -38,12 +38,10 @@ public final class MyersDiff<T> implements DiffAlgorithm<T> {
private final BiPredicate<T, T> DEFAULT_EQUALIZER = Object::equals; private final BiPredicate<T, T> DEFAULT_EQUALIZER = Object::equals;
private final BiPredicate<T, T> equalizer; private final BiPredicate<T, T> equalizer;
public MyersDiff() { public MyersDiff() {
equalizer = DEFAULT_EQUALIZER; equalizer = DEFAULT_EQUALIZER;
} }
public MyersDiff(final BiPredicate<T, T> equalizer) { public MyersDiff(final BiPredicate<T, T> equalizer) {
Objects.requireNonNull(equalizer, "equalizer must not be null"); Objects.requireNonNull(equalizer, "equalizer must not be null");
this.equalizer = equalizer; this.equalizer = equalizer;
@@ -64,9 +62,8 @@ public final class MyersDiff<T> implements DiffAlgorithm<T> {
} }
/** /**
* Computes the minimum diffpath that expresses de differences between the * Computes the minimum diffpath that expresses de differences between the original and revised sequences, according
* original and revised sequences, according to Gene Myers differencing * to Gene Myers differencing algorithm.
* algorithm.
* *
* @param orig The original sequence. * @param orig The original sequence.
* @param rev The revised sequence. * @param rev The revised sequence.
@@ -138,8 +135,7 @@ public final class MyersDiff<T> implements DiffAlgorithm<T> {
* @param orig The original sequence. * @param orig The original sequence.
* @param rev The revised sequence. * @param rev The revised sequence.
* @return A {@link Patch} script corresponding to the path. * @return A {@link Patch} script corresponding to the path.
* @throws DifferentiationFailedException if a {@link Patch} could not be * @throws DifferentiationFailedException if a {@link Patch} could not be built from the given path.
* built from the given path.
*/ */
private List<Change> buildRevision(PathNode actualPath, List<T> orig, List<T> rev) { private List<Change> buildRevision(PathNode actualPath, List<T> orig, List<T> rev) {
Objects.requireNonNull(actualPath, "path is null"); Objects.requireNonNull(actualPath, "path is null");

View File

@@ -61,7 +61,7 @@ public final class PathNode {
if (snake) { if (snake) {
this.prev = prev; this.prev = prev;
} else { } else {
this.prev = (prev == null ? null : prev.previousSnake()); this.prev = prev == null ? null : prev.previousSnake();
} }
this.snake = snake; 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 * Skips sequences of {@link DiffNode DiffNodes} until a {@link Snake} or bootstrap node is found, or the end of the
* found, or the end of the path is reached. * path is reached.
* *
* @return The next first {@link Snake} or bootstrap node in the path, or <code>null</code> if * @return The next first {@link Snake} or bootstrap node in the path, or <code>null</code> if none found.
* none found.
*/ */
public final PathNode previousSnake() { public final PathNode previousSnake() {
if (isBootstrap()) { if (isBootstrap()) {

View File

@@ -26,10 +26,9 @@ import java.util.List;
* Holds the information about the part of text involved in the diff process * Holds the information about the part of text involved in the diff process
* *
* <p> * <p>
* Text is represented as <code>Object[]</code> because the diff engine is capable of handling more * Text is represented as <code>Object[]</code> because the diff engine is capable of handling more than plain ascci. In
* than plain ascci. In fact, arrays or lists of any type that implements * fact, arrays or lists of any type that implements {@link java.lang.Object#hashCode hashCode()} and
* {@link java.lang.Object#hashCode hashCode()} and {@link java.lang.Object#equals equals()} * {@link java.lang.Object#equals equals()} correctly can be subject to differencing using this library.
* correctly can be subject to differencing using this library.
* </p> * </p>
* *
* @author <a href="dm.naumenko@gmail.com>Dmitry Naumenko</a> * @author <a href="dm.naumenko@gmail.com>Dmitry Naumenko</a>

View File

@@ -32,7 +32,6 @@ public enum DeltaType {
* An insert into the original. * An insert into the original.
*/ */
INSERT, INSERT,
/** /**
* An do nothing. * An do nothing.
*/ */

View File

@@ -25,7 +25,6 @@ import static com.github.difflib.patch.DeltaType.INSERT;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import static java.util.Comparator.comparing; import static java.util.Comparator.comparing;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
@@ -37,7 +36,15 @@ import java.util.ListIterator;
*/ */
public final class Patch<T> { public final class Patch<T> {
private final List<Delta<T>> deltas = new LinkedList<>(); private final List<Delta<T>> deltas;
public Patch() {
this(10);
}
public Patch(int estimatedPatchSize) {
deltas = new ArrayList<>(estimatedPatchSize);
}
/** /**
* Apply this patch to the given target * Apply this patch to the given target
@@ -46,7 +53,7 @@ public final class Patch<T> {
* @throws PatchFailedException if can't apply patch * @throws PatchFailedException if can't apply patch
*/ */
public List<T> applyTo(List<T> target) throws PatchFailedException { public List<T> applyTo(List<T> target) throws PatchFailedException {
List<T> result = new LinkedList<>(target); List<T> result = new ArrayList<>(target);
ListIterator<Delta<T>> it = getDeltas().listIterator(deltas.size()); ListIterator<Delta<T>> it = getDeltas().listIterator(deltas.size());
while (it.hasPrevious()) { while (it.hasPrevious()) {
Delta<T> delta = it.previous(); Delta<T> delta = it.previous();
@@ -62,7 +69,7 @@ public final class Patch<T> {
* @return the restored text * @return the restored text
*/ */
public List<T> restore(List<T> target) { public List<T> restore(List<T> target) {
List<T> result = new LinkedList<>(target); List<T> result = new ArrayList<>(target);
ListIterator<Delta<T>> it = getDeltas().listIterator(deltas.size()); ListIterator<Delta<T>> it = getDeltas().listIterator(deltas.size());
while (it.hasPrevious()) { while (it.hasPrevious()) {
Delta<T> delta = it.previous(); Delta<T> delta = it.previous();
@@ -96,7 +103,7 @@ public final class Patch<T> {
} }
public static <T> Patch<T> generate(List<T> original, List<T> revised, List<Change> changes) { public static <T> Patch<T> generate(List<T> original, List<T> revised, List<Change> changes) {
Patch<T> patch = new Patch<>(); Patch<T> patch = new Patch<>(changes.size());
for (Change change : changes) { for (Change change : changes) {
Chunk<T> orgChunk = new Chunk<>(change.startOriginal, new ArrayList<>(original.subList(change.startOriginal, change.endOriginal))); Chunk<T> orgChunk = new Chunk<>(change.startOriginal, new ArrayList<>(original.subList(change.startOriginal, change.endOriginal)));
Chunk<T> revChunk = new Chunk<>(change.startRevised, new ArrayList<>(revised.subList(change.startRevised, change.endRevised))); Chunk<T> revChunk = new Chunk<>(change.startRevised, new ArrayList<>(revised.subList(change.startRevised, change.endRevised)));

View File

@@ -22,8 +22,7 @@ package com.github.difflib.text;
import java.io.Serializable; import java.io.Serializable;
/** /**
* Describes the diff row in form [tag, oldLine, newLine) for showing the difference between two * Describes the diff row in form [tag, oldLine, newLine) for showing the difference between two texts
* texts
* *
* @author <a href="dm.naumenko@gmail.com">Dmitry Naumenko</a> * @author <a href="dm.naumenko@gmail.com">Dmitry Naumenko</a>
*/ */

View File

@@ -35,10 +35,9 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/** /**
* This class for generating DiffRows for side-by-sidy view. You can customize the way of * This class for generating DiffRows for side-by-sidy view. You can customize the way of generating. For example, show
* generating. For example, show inline diffs on not, ignoring white spaces or/and blank lines and * inline diffs on not, ignoring white spaces or/and blank lines and so on. All parameters for generating are optional.
* so on. All parameters for generating are optional. If you do not specify them, the class will use * If you do not specify them, the class will use the default values.
* the default values.
* *
* These values are: showInlineDiffs = false; ignoreWhiteSpaces = true; ignoreBlankLines = true; ... * These values are: showInlineDiffs = false; ignoreWhiteSpaces = true; ignoreBlankLines = true; ...
* *
@@ -48,19 +47,38 @@ import java.util.regex.Pattern;
* </code> * </code>
*/ */
public class DiffRowGenerator { public class DiffRowGenerator {
public static final Pattern SPLIT_BY_WORD_PATTERN = Pattern.compile("\\s+|[,.\\[\\](){}/\\\\*+\\-#]");
public static final BiPredicate<String, String> IGNORE_WHITESPACE_EQUALIZER = (original, revised) public static final BiPredicate<String, String> IGNORE_WHITESPACE_EQUALIZER = (original, revised)
-> original.trim().replaceAll("\\s+", " ").equals(revised.trim().replaceAll("\\s+", " ")); -> original.trim().replaceAll("\\s+", " ").equals(revised.trim().replaceAll("\\s+", " "));
public static final BiPredicate<String, String> DEFAULT_EQUALIZER = Object::equals; public static final BiPredicate<String, String> DEFAULT_EQUALIZER = Object::equals;
private static final Pattern SPLIT_PATTERN = Pattern.compile("\\s+|[,.\\[\\](){}/\\\\*+\\-#]");
/**
* Splitting lines by word to achieve word by word diff checking.
*/
public static final Function<String, List<String>> SPLITTER_BY_WORD = line -> splitStringPreserveDelimiter(line, SPLIT_BY_WORD_PATTERN);
/**
* Splitting lines by character to achieve char by char diff checking.
*/
public static final Function<String, List<String>> SPLITTER_BY_CHARACTER = line -> {
List<String> list = new ArrayList<>(line.length());
for (Character character : line.toCharArray()) {
list.add(character.toString());
}
return list;
};
private final boolean showInlineDiffs; private final boolean showInlineDiffs;
private final boolean ignoreWhiteSpaces; private final boolean ignoreWhiteSpaces;
private final Function<Boolean, String> oldTag; private final Function<Boolean, String> oldTag;
private final Function<Boolean, String> newTag; private final Function<Boolean, String> newTag;
private final boolean inlineDiffByWord; private final Function<String, List<String>> inlineDiffSplitter;
private final int columnWidth; private final int columnWidth;
private final BiPredicate<String, String> equalizer; private final BiPredicate<String, String> equalizer;
private final boolean mergeOriginalRevised; private final boolean mergeOriginalRevised;
private final boolean reportLinesUnchanged;
/** /**
* This class used for building the DiffRowGenerator. * This class used for building the DiffRowGenerator.
@@ -76,9 +94,10 @@ public class DiffRowGenerator {
private Function<Boolean, String> oldTag = f -> f ? "<span class=\"editOldInline\">" : "</span>"; private Function<Boolean, String> oldTag = f -> f ? "<span class=\"editOldInline\">" : "</span>";
private Function<Boolean, String> newTag = f -> f ? "<span class=\"editNewInline\">" : "</span>"; private Function<Boolean, String> newTag = f -> f ? "<span class=\"editNewInline\">" : "</span>";
private int columnWidth = 80; private int columnWidth = 0;
private boolean mergeOriginalRevised = false; private boolean mergeOriginalRevised = false;
private boolean inlineDiffByWord = false; private boolean reportLinesUnchanged = false;
private Function<String, List<String>> inlineDiffSplitter = SPLITTER_BY_CHARACTER;
private Builder() { private Builder() {
} }
@@ -105,6 +124,17 @@ public class DiffRowGenerator {
return this; return this;
} }
/**
* Give the originial old and new text lines to Diffrow without any additional processing.
*
* @param val the value to set. Default: false.
* @return builder with configured reportLinesUnWrapped parameter
*/
public Builder reportLinesUnchanged(final boolean val) {
reportLinesUnchanged = val;
return this;
}
/** /**
* Generator for Old-Text-Tags. * Generator for Old-Text-Tags.
* *
@@ -130,11 +160,11 @@ public class DiffRowGenerator {
/** /**
* Set the column with of generated lines of original and revised texts. * Set the column with of generated lines of original and revised texts.
* *
* @param width the width to set. Making it < 0 doesn't have any sense. Default 80. @return * @param width the width to set. Making it < 0 doesn't have any sense. Default 80. @return builder with config
* builder with config ured ignoreBlankLines parameter * ured ignoreBlankLines parameter
*/ */
public Builder columnWidth(int width) { public Builder columnWidth(int width) {
if (width > 0) { if (width >= 0) {
columnWidth = width; columnWidth = width;
} }
return this; return this;
@@ -150,8 +180,7 @@ public class DiffRowGenerator {
} }
/** /**
* Merge the complete result within the original text. This makes sense for one line * Merge the complete result within the original text. This makes sense for one line display.
* display.
* *
* @param mergeOriginalRevised * @param mergeOriginalRevised
* @return * @return
@@ -162,11 +191,17 @@ public class DiffRowGenerator {
} }
/** /**
* Per default each character is separatly processed. This variant introduces processing by * Per default each character is separatly processed. This variant introduces processing by word, which should
* word, which should deliver no in word changes. * deliver no in word changes.
*/ */
public Builder inlineDiffByWord(boolean inlineDiffByWord) { public Builder inlineDiffByWord(boolean inlineDiffByWord) {
this.inlineDiffByWord = inlineDiffByWord; inlineDiffSplitter = inlineDiffByWord?SPLITTER_BY_WORD:SPLITTER_BY_CHARACTER;
return this;
}
public Builder inlineDiffBySplitter(Function<String, List<String>> inlineDiffSplitter) {
this.inlineDiffSplitter = inlineDiffSplitter;
return this; return this;
} }
} }
@@ -182,13 +217,16 @@ public class DiffRowGenerator {
newTag = builder.newTag; newTag = builder.newTag;
columnWidth = builder.columnWidth; columnWidth = builder.columnWidth;
mergeOriginalRevised = builder.mergeOriginalRevised; mergeOriginalRevised = builder.mergeOriginalRevised;
inlineDiffByWord = builder.inlineDiffByWord; inlineDiffSplitter = builder.inlineDiffSplitter;
equalizer = ignoreWhiteSpaces ? IGNORE_WHITESPACE_EQUALIZER : DEFAULT_EQUALIZER; equalizer = ignoreWhiteSpaces ? IGNORE_WHITESPACE_EQUALIZER : DEFAULT_EQUALIZER;
reportLinesUnchanged = builder.reportLinesUnchanged;
Objects.requireNonNull(inlineDiffSplitter);
} }
/** /**
* Get the DiffRows describing the difference between original and revised texts using the given * Get the DiffRows describing the difference between original and revised texts using the given patch. Useful for
* patch. Useful for displaying side-by-side diff. * displaying side-by-side diff.
* *
* @param original the original text * @param original the original text
* @param revised the revised text * @param revised the revised text
@@ -198,14 +236,25 @@ public class DiffRowGenerator {
return generateDiffRows(original, DiffUtils.diff(original, revised, equalizer)); return generateDiffRows(original, DiffUtils.diff(original, revised, equalizer));
} }
private String preprocessLine(String line) {
if (columnWidth == 0) {
return StringUtils.normalize(line);
} else {
return StringUtils.wrapText(StringUtils.normalize(line), columnWidth);
}
}
private DiffRow buildDiffRow(Tag type, String orgline, String newline) { private DiffRow buildDiffRow(Tag type, String orgline, String newline) {
String wrapOrg = StringUtils.wrapText(StringUtils.normalize(orgline), columnWidth); if (reportLinesUnchanged) {
return new DiffRow(type, orgline, newline);
} else {
String wrapOrg = preprocessLine(orgline);
if (Tag.DELETE == type) { if (Tag.DELETE == type) {
if (mergeOriginalRevised || showInlineDiffs) { if (mergeOriginalRevised || showInlineDiffs) {
wrapOrg = oldTag.apply(true) + wrapOrg + oldTag.apply(false); wrapOrg = oldTag.apply(true) + wrapOrg + oldTag.apply(false);
} }
} }
String wrapNew = StringUtils.wrapText(StringUtils.normalize(newline), columnWidth); String wrapNew = preprocessLine(newline);
if (Tag.INSERT == type) { if (Tag.INSERT == type) {
if (mergeOriginalRevised) { if (mergeOriginalRevised) {
wrapOrg = newTag.apply(true) + wrapNew + newTag.apply(false); wrapOrg = newTag.apply(true) + wrapNew + newTag.apply(false);
@@ -215,6 +264,7 @@ public class DiffRowGenerator {
} }
return new DiffRow(type, wrapOrg, wrapNew); return new DiffRow(type, wrapOrg, wrapNew);
} }
}
private DiffRow buildDiffRowWithoutNormalizing(Tag type, String orgline, String newline) { private DiffRow buildDiffRowWithoutNormalizing(Tag type, String orgline, String newline) {
return new DiffRow(type, return new DiffRow(type,
@@ -223,8 +273,8 @@ public class DiffRowGenerator {
} }
/** /**
* Generates the DiffRows describing the difference between original and revised texts using the * Generates the DiffRows describing the difference between original and revised texts using the given patch. Useful
* given patch. Useful for displaying side-by-side diff. * for displaying side-by-side diff.
* *
* @param original the original text * @param original the original text
* @param revised the revised text * @param revised the revised text
@@ -291,20 +341,11 @@ public class DiffRowGenerator {
List<String> rev = StringUtils.normalize(delta.getRevised().getLines()); List<String> rev = StringUtils.normalize(delta.getRevised().getLines());
List<String> origList; List<String> origList;
List<String> revList; List<String> revList;
String joinedOrig = String.join("\n", orig);
String joinedRev = String.join("\n", rev);
if (inlineDiffByWord) { origList = inlineDiffSplitter.apply(joinedOrig);
origList = splitStringPreserveDelimiter(String.join("\n", orig)); revList = inlineDiffSplitter.apply(joinedRev);
revList = splitStringPreserveDelimiter(String.join("\n", rev));
} else {
origList = new LinkedList<>();
revList = new LinkedList<>();
for (Character character : String.join("\n", orig).toCharArray()) {
origList.add(character.toString());
}
for (Character character : String.join("\n", rev).toCharArray()) {
revList.add(character.toString());
}
}
List<Delta<String>> inlineDeltas = DiffUtils.diff(origList, revList).getDeltas(); List<Delta<String>> inlineDeltas = DiffUtils.diff(origList, revList).getDeltas();
@@ -367,8 +408,7 @@ public class DiffRowGenerator {
/** /**
* Wrap the elements in the sequence with the given tag * Wrap the elements in the sequence with the given tag
* *
* @param startPosition the position from which tag should start. The counting start from a * @param startPosition the position from which tag should start. The counting start from a zero.
* zero.
* @param endPosition the position before which tag should should be closed. * @param endPosition the position before which tag should should be closed.
* @param tag the tag name without angle brackets, just a word * @param tag the tag name without angle brackets, just a word
* @param cssClass the optional css class * @param cssClass the optional css class
@@ -379,7 +419,7 @@ public class DiffRowGenerator {
sequence.add(endPosition, generator.apply(false)); sequence.add(endPosition, generator.apply(false));
} }
protected final static List<String> splitStringPreserveDelimiter(String str) { protected final static List<String> splitStringPreserveDelimiter(String str, Pattern SPLIT_PATTERN) {
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
if (str != null) { if (str != null) {
Matcher matcher = SPLIT_PATTERN.matcher(str); Matcher matcher = SPLIT_PATTERN.matcher(str);

View File

@@ -58,8 +58,11 @@ final class StringUtils {
* @return the wrapped text * @return the wrapped text
*/ */
public static String wrapText(String line, int columnWidth) { public static String wrapText(String line, int columnWidth) {
if (columnWidth <= 0) { if (columnWidth < 0) {
throw new IllegalArgumentException("columnWidth may not be less or equal 0"); throw new IllegalArgumentException("columnWidth may not be less 0");
}
if (columnWidth == 0) {
return line;
} }
int length = line.length(); int length = line.length();
int delimiter = "<br/>".length(); int delimiter = "<br/>".length();

View File

@@ -1,6 +1,5 @@
package com.github.difflib; package com.github.difflib;
import com.github.difflib.DiffUtils;
import com.github.difflib.algorithm.DiffException; import com.github.difflib.algorithm.DiffException;
import com.github.difflib.patch.ChangeDelta; import com.github.difflib.patch.ChangeDelta;
import com.github.difflib.patch.Chunk; import com.github.difflib.patch.Chunk;

View File

@@ -1,7 +1,5 @@
package com.github.difflib; package com.github.difflib;
import com.github.difflib.DiffUtils;
import com.github.difflib.UnifiedDiffUtils;
import com.github.difflib.algorithm.DiffException; import com.github.difflib.algorithm.DiffException;
import com.github.difflib.patch.Patch; import com.github.difflib.patch.Patch;
import com.github.difflib.patch.PatchFailedException; import com.github.difflib.patch.PatchFailedException;

View File

@@ -7,6 +7,7 @@ package com.github.difflib;
* *
*/ */
public final class TestConstants { public final class TestConstants {
public static final String BASE_FOLDER_RESOURCES = "target/test-classes/"; 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. Ends with {@link #FS}.

View File

@@ -15,22 +15,17 @@
*/ */
package com.github.difflib.algorithm.jgit; 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.algorithm.DiffException;
import com.github.difflib.patch.Patch; import com.github.difflib.patch.Patch;
import com.github.difflib.patch.PatchFailedException; import com.github.difflib.patch.PatchFailedException;
import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.zip.ZipFile;
import org.junit.After; import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;
import static org.junit.Assert.*;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.*;
/** /**
* *

View File

@@ -15,22 +15,20 @@
*/ */
package com.github.difflib.algorithm.jgit; package com.github.difflib.algorithm.jgit;
import com.github.difflib.algorithm.jgit.HistogramDiff;
import static com.github.difflib.DiffUtilsTest.readStringListFromInputStream; import static com.github.difflib.DiffUtilsTest.readStringListFromInputStream;
import com.github.difflib.TestConstants; import com.github.difflib.TestConstants;
import com.github.difflib.algorithm.DiffException; import com.github.difflib.algorithm.DiffException;
import com.github.difflib.patch.Patch; import com.github.difflib.patch.Patch;
import com.github.difflib.patch.PatchFailedException; import com.github.difflib.patch.PatchFailedException;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import org.junit.After; import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;
import static org.junit.Assert.*;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.*;
/** /**
* *
@@ -57,7 +55,6 @@ public class LRHistogramDiffTest {
public void tearDown() { public void tearDown() {
} }
@Test @Test
public void testPossibleDiffHangOnLargeDatasetDnaumenkoIssue26() throws IOException, DiffException, PatchFailedException { public void testPossibleDiffHangOnLargeDatasetDnaumenkoIssue26() throws IOException, DiffException, PatchFailedException {
ZipFile zip = new ZipFile(TestConstants.MOCK_FOLDER + "/large_dataset1.zip"); ZipFile zip = new ZipFile(TestConstants.MOCK_FOLDER + "/large_dataset1.zip");

View File

@@ -15,18 +15,12 @@
*/ */
package com.github.difflib.algorithm.myers; 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.algorithm.DiffException;
import com.github.difflib.patch.Patch; import com.github.difflib.patch.Patch;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; 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 static org.junit.Assert.*;
import org.junit.Test;
/** /**
* *

View File

@@ -1,7 +1,5 @@
package com.github.difflib.patch; 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.DiffUtils;
import com.github.difflib.algorithm.DiffException; import com.github.difflib.algorithm.DiffException;
import java.util.Arrays; import java.util.Arrays;

View File

@@ -1,10 +1,9 @@
package com.github.difflib.text; package com.github.difflib.text;
import com.github.difflib.text.DiffRow;
import com.github.difflib.text.DiffRowGenerator;
import com.github.difflib.algorithm.DiffException; import com.github.difflib.algorithm.DiffException;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.regex.Pattern;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import org.junit.Test; import org.junit.Test;
@@ -25,6 +24,20 @@ public class DiffRowGeneratorTest {
assertEquals(3, rows.size()); assertEquals(3, rows.size());
} }
@Test
public void testGenerator_Default2() throws DiffException {
String first = "anything \n \nother";
String second = "anything\n\nother";
DiffRowGenerator generator = DiffRowGenerator.create()
.columnWidth(0) // do not wrap
.build();
List<DiffRow> rows = generator.generateDiffRows(split(first), split(second));
print(rows);
assertEquals(3, rows.size());
}
@Test @Test
public void testGenerator_InlineDiff() throws DiffException { public void testGenerator_InlineDiff() throws DiffException {
String first = "anything \n \nother"; String first = "anything \n \nother";
@@ -159,6 +172,7 @@ public class DiffRowGeneratorTest {
.showInlineDiffs(true) .showInlineDiffs(true)
.mergeOriginalRevised(true) .mergeOriginalRevised(true)
.inlineDiffByWord(true) .inlineDiffByWord(true)
.columnWidth(80)
.build(); .build();
List<DiffRow> rows = generator.generateDiffRows(Arrays.asList("Test feature"), Arrays.asList("ester feature best")); List<DiffRow> rows = generator.generateDiffRows(Arrays.asList("Test feature"), Arrays.asList("ester feature best"));
print(rows); print(rows);
@@ -169,14 +183,14 @@ public class DiffRowGeneratorTest {
@Test @Test
public void testSplitString() { public void testSplitString() {
List<String> list = DiffRowGenerator.splitStringPreserveDelimiter("test,test2"); List<String> list = DiffRowGenerator.splitStringPreserveDelimiter("test,test2", DiffRowGenerator.SPLIT_BY_WORD_PATTERN);
assertEquals(3, list.size()); assertEquals(3, list.size());
assertEquals("[test, ,, test2]", list.toString()); assertEquals("[test, ,, test2]", list.toString());
} }
@Test @Test
public void testSplitString2() { public void testSplitString2() {
List<String> list = DiffRowGenerator.splitStringPreserveDelimiter("test , test2"); List<String> list = DiffRowGenerator.splitStringPreserveDelimiter("test , test2", DiffRowGenerator.SPLIT_BY_WORD_PATTERN);
System.out.println(list); System.out.println(list);
assertEquals(5, list.size()); assertEquals(5, list.size());
assertEquals("[test, , ,, , test2]", list.toString()); assertEquals("[test, , ,, , test2]", list.toString());
@@ -184,13 +198,12 @@ public class DiffRowGeneratorTest {
@Test @Test
public void testSplitString3() { public void testSplitString3() {
List<String> list = DiffRowGenerator.splitStringPreserveDelimiter("test,test2,"); List<String> list = DiffRowGenerator.splitStringPreserveDelimiter("test,test2,", DiffRowGenerator.SPLIT_BY_WORD_PATTERN);
System.out.println(list); System.out.println(list);
assertEquals(4, list.size()); assertEquals(4, list.size());
assertEquals("[test, ,, test2, ,]", list.toString()); assertEquals("[test, ,, test2, ,]", list.toString());
} }
@Test @Test
public void testGeneratorExample1() throws DiffException { public void testGeneratorExample1() throws DiffException {
DiffRowGenerator generator = DiffRowGenerator.create() DiffRowGenerator generator = DiffRowGenerator.create()
@@ -232,4 +245,41 @@ public class DiffRowGeneratorTest {
assertEquals("This is a test ~senctence~.", rows.get(0).getOldLine()); assertEquals("This is a test ~senctence~.", rows.get(0).getOldLine());
assertEquals("This is a test **for diffutils**.", rows.get(0).getNewLine()); 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)
.reportLinesUnchanged(true)
.build();
List<DiffRow> rows = generator.generateDiffRows(split(first), split(second));
print(rows);
assertEquals(3, rows.size());
assertEquals("[CHANGE,anything ,anything]", rows.get(0).toString());
assertEquals("[CHANGE, ,]", rows.get(1).toString());
assertEquals("[EQUAL,other,other]", rows.get(2).toString());
}
@Test
public void testGeneratorIssue14() throws DiffException {
DiffRowGenerator generator = DiffRowGenerator.create()
.showInlineDiffs(true)
.mergeOriginalRevised(true)
.inlineDiffBySplitter(line -> DiffRowGenerator.splitStringPreserveDelimiter(line, Pattern.compile(",")))
.oldTag(f -> "~")
.newTag(f -> "**")
.build();
List<DiffRow> rows = generator.generateDiffRows(
Arrays.asList("J. G. Feldstein, Chair"),
Arrays.asList("T. P. Pastor, Chair"));
System.out.println(rows.get(0).getOldLine());
assertEquals(1, rows.size());
assertEquals("~J. G. Feldstein~**T. P. Pastor**, Chair", rows.get(0).getOldLine());
}
} }

View File

@@ -15,10 +15,9 @@
*/ */
package com.github.difflib.text; package com.github.difflib.text;
import com.github.difflib.text.StringUtils;
import java.util.Collections; import java.util.Collections;
import org.junit.Test;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import org.junit.Test;
/** /**
* *
@@ -62,7 +61,7 @@ public class StringUtilsTest {
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void testWrapText_String_int_zero() { public void testWrapText_String_int_zero() {
assertEquals("test", StringUtils.wrapText("test", 0)); assertEquals("test", StringUtils.wrapText("test", -1));
} }
} }