Top Fields Constructors Methods
com.github.difflib

public final Class UnifiedDiffUtils

extends Object
Class Inheritance
Imports
com.github.difflib.patch.ChangeDelta, .Chunk, .AbstractDelta, .Patch, java.util.ArrayList, .HashMap, .List, .Map, .Optional, java.util.regex.Matcher, .Pattern, java.util.stream.Collectors

Author
toben

Field Summary

Modifier and TypeField and Description
private static final String
private static final Pattern

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static List<String>
generateOriginalAndDiff(List<String>
Original file content
original
,
List<String>
revised file content
revised
)

Compare the differences between two files and return to the original file and diff format (This method compares the original file with the comparison file to obtain a diff, and inserts the diff into the corresponding position of the original file.

public static List<String>
generateOriginalAndDiff(List<String>
Original file content
original
,
List<String>
revised file content
revised
,
String
Original file name
originalFileName
,
String
revised file name
revisedFileName
)

Compare the differences between two files and return to the original file and diff format (This method compares the original file with the comparison file to obtain a diff, and inserts the diff into the corresponding position of the original file.

public static List<String>

Returns:

List of strings representing the Unified Diff representation of the Patch argument.
generateUnifiedDiff
(String
- Filename of the original (unrevised file)
originalFileName
,
String
- Filename of the revised file
revisedFileName
,
List<String>
- Lines of the original file
originalLines
,
Patch<String>
- Patch created by the diff() function
patch
,
int
- number of lines of context output around each difference in the file.
contextSize
)

generateUnifiedDiff takes a Patch and some other arguments, returning the Unified Diff format text representing the Patch.

private static List<String>

Returns:

list of String lines of code.
getDeltaText
(AbstractDelta<String>
- the Delta to output
delta
)

getDeltaText returns the lines to be added to the Unified Diff text from the Delta parameter.

private static List<String>
getOrigList(List<String> originalWithPrefix, int start, int end)

private static Map<String, Integer>
private static void
insert(List<String> result, List<String> noChangeContent)

private static List<String>
insertOrig(List<String> original, List<String> unifiedDiff)

private static void
insertOrig(List<List<String>> diffList, List<String> result, List<String> original)

public static Patch<String>

Returns:

the patch with deltas.
parseUnifiedDiff
(List<String>
the text in unified format
diff
)

Parse the given text in unified format and creates the list of deltas for it.

private static List<String>
processDeltas(List<String>
- the lines of the original file
origLines
,
List<AbstractDelta<String>>
- the Deltas to be output as a single block
deltas
,
int
- the number of lines of context to place around block
contextSize
,
boolean newFile)

processDeltas takes a list of Deltas and outputs them together in a single block of Unified-Diff-format text.

private static void
processLinesInPrevChunk(List<String[]> rawChunk, Patch<String> patch, int old_ln, int new_ln)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

NULL_FILE_INDICATORback to summary
private static final String NULL_FILE_INDICATOR
UNIFIED_DIFF_CHUNK_REGEXPback to summary
private static final Pattern UNIFIED_DIFF_CHUNK_REGEXP

Constructor Detail

UnifiedDiffUtilsback to summary
private UnifiedDiffUtils()

Method Detail

generateOriginalAndDiffback to summary
public static List<String> generateOriginalAndDiff(List<String> original, List<String> revised)

Compare the differences between two files and return to the original file and diff format (This method compares the original file with the comparison file to obtain a diff, and inserts the diff into the corresponding position of the original file. You can see all the differences and unmodified places from the original file. Also, this will be very easy and useful for making side-by-side comparison display applications, for example, if you use diff2html (https://github.com/rtfpessoa/diff2html#usage) Wait for tools to display your differences on html pages, you only need to insert the return value into your js code)

Parameters
original:List<String>

Original file content

revised:List<String>

revised file content

generateOriginalAndDiffback to summary
public static List<String> generateOriginalAndDiff(List<String> original, List<String> revised, String originalFileName, String revisedFileName)

Compare the differences between two files and return to the original file and diff format (This method compares the original file with the comparison file to obtain a diff, and inserts the diff into the corresponding position of the original file. You can see all the differences and unmodified places from the original file. Also, this will be very easy and useful for making side-by-side comparison display applications, for example, if you use diff2html (https://github.com/rtfpessoa/diff2html#usage) Wait for tools to display your differences on html pages, you only need to insert the return value into your js code)

Parameters
original:List<String>

Original file content

revised:List<String>

revised file content

originalFileName:String

Original file name

revisedFileName:String

revised file name

generateUnifiedDiffback to summary
public static List<String> generateUnifiedDiff(String originalFileName, String revisedFileName, List<String> originalLines, Patch<String> patch, int contextSize)

generateUnifiedDiff takes a Patch and some other arguments, returning the Unified Diff format text representing the Patch. Author: Bill James ([email protected]).

Parameters
originalFileName:String

- Filename of the original (unrevised file)

revisedFileName:String

- Filename of the revised file

originalLines:List<String>

- Lines of the original file

patch:Patch<String>

- Patch created by the diff() function

contextSize:int

- number of lines of context output around each difference in the file.

Returns:List<String>

List of strings representing the Unified Diff representation of the Patch argument.

getDeltaTextback to summary
private static List<String> getDeltaText(AbstractDelta<String> delta)

getDeltaText returns the lines to be added to the Unified Diff text from the Delta parameter. Author: Bill James ([email protected]).

Parameters
delta:AbstractDelta<String>

- the Delta to output

Returns:List<String>

list of String lines of code.

getOrigListback to summary
private static List<String> getOrigList(List<String> originalWithPrefix, int start, int end)
getRowMapback to summary
private static Map<String, Integer> getRowMap(String str)
insertback to summary
private static void insert(List<String> result, List<String> noChangeContent)
insertOrigback to summary
private static List<String> insertOrig(List<String> original, List<String> unifiedDiff)
insertOrigback to summary
private static void insertOrig(List<List<String>> diffList, List<String> result, List<String> original)
parseUnifiedDiffback to summary
public static Patch<String> parseUnifiedDiff(List<String> diff)

Parse the given text in unified format and creates the list of deltas for it.

Parameters
diff:List<String>

the text in unified format

Returns:Patch<String>

the patch with deltas.

processDeltasback to summary
private static List<String> processDeltas(List<String> origLines, List<AbstractDelta<String>> deltas, int contextSize, boolean newFile)

processDeltas takes a list of Deltas and outputs them together in a single block of Unified-Diff-format text. Author: Bill James ([email protected]).

Parameters
origLines:List<String>

- the lines of the original file

deltas:List<AbstractDelta<String>>

- the Deltas to be output as a single block

contextSize:int

- the number of lines of context to place around block

processLinesInPrevChunkback to summary
private static void processLinesInPrevChunk(List<String[]> rawChunk, Patch<String> patch, int old_ln, int new_ln)