com.liferay.portal.util
Class DiffImpl

java.lang.Object
  extended by com.liferay.portal.util.DiffImpl
All Implemented Interfaces:
com.liferay.portal.kernel.util.Diff

public class DiffImpl
extends java.lang.Object
implements com.liferay.portal.kernel.util.Diff

View Source

This class can compare two different versions of a text. Source refers to the earliest version of the text and target refers to a modified version of source. Changes are considered either as a removal from the source or as an addition to the target. This class detects changes to an entire line and also detects changes within lines, such as, removal or addition of characters. Take a look at DiffTest to see the expected inputs and outputs.

Author:
Bruno Farache

Field Summary
 
Fields inherited from interface com.liferay.portal.kernel.util.Diff
CLOSE_DEL, CLOSE_INS, CONTEXT_LINE, OPEN_DEL, OPEN_INS
 
Constructor Summary
DiffImpl()
           
 
Method Summary
 java.util.List<com.liferay.portal.kernel.util.DiffResult>[] diff(java.io.Reader source, java.io.Reader target)
          This is a diff method with default values.
 java.util.List<com.liferay.portal.kernel.util.DiffResult>[] diff(java.io.Reader source, java.io.Reader target, java.lang.String addedMarkerStart, java.lang.String addedMarkerEnd, java.lang.String deletedMarkerStart, java.lang.String deletedMarkerEnd, int margin)
          The main entrance of this class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DiffImpl

public DiffImpl()
Method Detail

diff

public java.util.List<com.liferay.portal.kernel.util.DiffResult>[] diff(java.io.Reader source,
                                                                        java.io.Reader target)
This is a diff method with default values.

Specified by:
diff in interface com.liferay.portal.kernel.util.Diff
Parameters:
source - the Reader of the source text
target - the Reader of the target text
Returns:
an array containing two lists of DiffResults, the first element contains DiffResults related to changes in source and the second element to changes in target

diff

public java.util.List<com.liferay.portal.kernel.util.DiffResult>[] diff(java.io.Reader source,
                                                                        java.io.Reader target,
                                                                        java.lang.String addedMarkerStart,
                                                                        java.lang.String addedMarkerEnd,
                                                                        java.lang.String deletedMarkerStart,
                                                                        java.lang.String deletedMarkerEnd,
                                                                        int margin)
The main entrance of this class. This method will compare the two texts, highlight the changes by enclosing them with markers and return a list of DiffResults.

Specified by:
diff in interface com.liferay.portal.kernel.util.Diff
Parameters:
source - the Reader of the source text, this can be for example, an instance of FileReader or StringReader
target - the Reader of the target text
addedMarkerStart - the initial marker for highlighting additions
addedMarkerEnd - the end marker for highlighting additions
deletedMarkerStart - the initial marker for highlighting removals
deletedMarkerEnd - the end marker for highlighting removals
margin - the number of lines that will be added before the first changed line
Returns:
an array containing two lists of DiffResults, the first element contains DiffResults related to changes in source and the second element to changes in target