Package de.skuzzle.difftool
Class StringDiff
- java.lang.Object
-
- de.skuzzle.difftool.StringDiff
-
public final class StringDiff extends java.lang.ObjectRepresents the difference between two Strings. The difference is calculated row wise by aDiffAlgorithmand is internally represented as a List ofDiffLine.Differences in line breaks are not part of the actual diff but will be determined as well.
Whether other whitespaces are subject to comparison depends on the used DiffAlgorithm.A StringDiff can be rendered as a nice human readable String using a
DiffRenderer. Rendering behavior can be fine tuned by providing aDiffSettingsinstance.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanhasDifference()Whether the compared Strings differ in either line separators or at least one text difference was found.booleanhasLineSeparatorDifference()Whether compared Strings differed in line separators.booleanhasTextDifference()Whether at least one text difference has been found.LineSeparatorleftLineSeparator()Returns theLineSeparatorfor the left file of the comparison.LineSeparatorrightLineSeparator()Returns theLineSeparatorof the right file of the comparison.static StringDiffsimple(java.lang.String left, java.lang.String right)java.util.List<DiffLine>textDifferences()Returns the internal list of differences (read-only).java.lang.StringtoString()Creates a unified rendered diff of this StringDiff using defaultDiffSettings.java.lang.StringtoString(DiffRenderer diffRenderer)java.lang.StringtoString(DiffRenderer diffRenderer, DiffSettings diffSettings)Creates a String representation of this diff via the givenDiffRendererusing givenDiffSettings.static StringDiffusing(DiffAlgorithm algorithm, java.lang.String left, java.lang.String right)static StringDiffusing(DiffAlgorithm algorithm, java.util.List<java.lang.String> left, java.util.List<java.lang.String> right)
-
-
-
Method Detail
-
simple
public static StringDiff simple(java.lang.String left, java.lang.String right)
-
using
public static StringDiff using(DiffAlgorithm algorithm, java.util.List<java.lang.String> left, java.util.List<java.lang.String> right)
-
using
public static StringDiff using(DiffAlgorithm algorithm, java.lang.String left, java.lang.String right)
-
textDifferences
public java.util.List<DiffLine> textDifferences()
Returns the internal list of differences (read-only).- Returns:
- The list of differences.
-
leftLineSeparator
public LineSeparator leftLineSeparator()
Returns theLineSeparatorfor the left file of the comparison.- Returns:
- The line separator.
-
rightLineSeparator
public LineSeparator rightLineSeparator()
Returns theLineSeparatorof the right file of the comparison.- Returns:
- The line separator.
-
hasDifference
public boolean hasDifference()
Whether the compared Strings differ in either line separators or at least one text difference was found. Equivalent tohasDifference = hasLineSeparatorDifference() || hasTextDifference();
- Returns:
- Whether any difference has been found.
-
hasTextDifference
public boolean hasTextDifference()
Whether at least one text difference has been found.- Returns:
- Whether at least one difference has been found.
-
hasLineSeparatorDifference
public boolean hasLineSeparatorDifference()
Whether compared Strings differed in line separators.- Returns:
- Whether compared Strings differed in line separators.
-
toString
public java.lang.String toString(DiffRenderer diffRenderer, DiffSettings diffSettings)
Creates a String representation of this diff via the givenDiffRendererusing givenDiffSettings.- Parameters:
diffRenderer- The renderer.diffSettings- The settings that will be passed to the renderer.- Returns:
- The String representation.
-
toString
public java.lang.String toString(DiffRenderer diffRenderer)
-
toString
public java.lang.String toString()
Creates a unified rendered diff of this StringDiff using defaultDiffSettings.- Overrides:
toStringin classjava.lang.Object- Returns:
- A String representation of this diff.
-
-