Top Description Fields Constructors Methods
org.assertj.core.util.diff

public Class DiffUtils

extends Object
Class Inheritance
Static Imports
org.assertj.core.util.Preconditions.checkArgument

Copy from https://code.google.com/p/java-diff-utils/.

Implements the difference and patching engine

Authors
Dmitry Naumenko, Bill James ([email protected])

Field Summary

Modifier and TypeField and Description
private static Pattern

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static <
the type of elements.
T
>
Patch<T>

Returns:

The patch describing the difference between the original and revised sequences. Never null.
diff
(List<T>
The original text. Must not be null.
original
,
List<T>
The revised text. Must not be null.
revised
)

Computes the difference between the original and revised list of elements with default diff algorithm

public static <
the type of elements.
T
>
Patch<T>

Returns:

The patch describing the difference between the original and revised sequences. Never null.
diff
(List<T>
The original text. Must not be null.
original
,
List<T>
The revised text. Must not be null.
revised
,
DiffAlgorithm<T>
The diff algorithm. Must not be null.
algorithm
)

Computes the difference between the original and revised list of elements with default diff algorithm

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)
original
,
String
Filename of the revised file
revised
,
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
(Delta<String>
the Delta to output
delta
)

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

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.

public static <
the type of elements.
T
>
List<T>

Returns:

the revised text
patch
(List<T>
the original text
original
,
Patch<T>
the given patch
patch
)

Patch the original text with given patch

private static List<String>

Returns:

the Unified-Diff-format text
processDeltas
(List<String>
the lines of the original file
origLines
,
List<Delta<String>>
the Deltas to be output as a single block
deltas
,
int
the number of lines of context to place around block
contextSize
)

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

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

unifiedDiffChunkReback to summary
private static Pattern unifiedDiffChunkRe

Constructor Detail

DiffUtilsback to summary
public DiffUtils()

Method Detail

diffback to summary
public static <T> Patch<T> diff(List<T> original, List<T> revised)

Computes the difference between the original and revised list of elements with default diff algorithm

Parameters
<T>
the type of elements.
original:List<T>

The original text. Must not be null.

revised:List<T>

The revised text. Must not be null.

Returns:Patch<T>

The patch describing the difference between the original and revised sequences. Never null.

diffback to summary
public static <T> Patch<T> diff(List<T> original, List<T> revised, DiffAlgorithm<T> algorithm)

Computes the difference between the original and revised list of elements with default diff algorithm

Parameters
<T>
the type of elements.
original:List<T>

The original text. Must not be null.

revised:List<T>

The revised text. Must not be null.

algorithm:DiffAlgorithm<T>

The diff algorithm. Must not be null.

Returns:Patch<T>

The patch describing the difference between the original and revised sequences. Never null.

generateUnifiedDiffback to summary
public static List<String> generateUnifiedDiff(String original, String revised, 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.

Parameters
original:String

Filename of the original (unrevised file)

revised: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(Delta<String> delta)

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

Parameters
delta:Delta<String>

the Delta to output

Returns:List<String>

list of String lines of code.

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.

patchback to summary
public static <T> List<T> patch(List<T> original, Patch<T> patch) throws IllegalStateException

Patch the original text with given patch

Parameters
<T>
the type of elements.
original:List<T>

the original text

patch:Patch<T>

the given patch

Returns:List<T>

the revised text

Exceptions
IllegalStateException:
if can't apply patch
processDeltasback to summary
private static List<String> processDeltas(List<String> origLines, List<Delta<String>> deltas, int contextSize)

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

Parameters
origLines:List<String>

the lines of the original file

deltas:List<Delta<String>>

the Deltas to be output as a single block

contextSize:int

the number of lines of context to place around block

Returns:List<String>

the Unified-Diff-format text