com.liferay.util.diff
Class DiffUtil
java.lang.Object
com.liferay.util.diff.DiffUtil
public class DiffUtil
- extends java.lang.Object
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
Method Summary |
static java.util.List<DiffResult>[] |
diff(java.io.Reader source,
java.io.Reader target)
This is a diff method with default values. |
static java.util.List<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 |
OPEN_INS
public static final java.lang.String OPEN_INS
- See Also:
- Constant Field Values
CLOSE_INS
public static final java.lang.String CLOSE_INS
- See Also:
- Constant Field Values
OPEN_DEL
public static final java.lang.String OPEN_DEL
- See Also:
- Constant Field Values
CLOSE_DEL
public static final java.lang.String CLOSE_DEL
- See Also:
- Constant Field Values
CONTEXT_LINE
public static final java.lang.String CONTEXT_LINE
- See Also:
- Constant Field Values
DiffUtil
public DiffUtil()
diff
public static java.util.List<DiffResult>[] diff(java.io.Reader source,
java.io.Reader target)
- This is a diff method with default values.
- Parameters:
source
- the Reader
of the source texttarget
- 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 static java.util.List<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
.
- Parameters:
source
- the Reader
of the source text, this can
be for example, an instance of FileReader or StringReadertarget
- the Reader
of the target textaddedMarkerStart
- the initial marker for highlighting
additionsaddedMarkerEnd
- the end marker for highlighting additionsdeletedMarkerStart
- the initial marker for highlighting
removalsdeletedMarkerEnd
- the end marker for highlighting removalsmargin
- 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