Package org.outerj.daisy.diff.html
Class TextNodeComparator
- java.lang.Object
-
- org.outerj.daisy.diff.html.TextNodeComparator
-
- All Implemented Interfaces:
Iterable<TextNode>
,IRangeComparator
public class TextNodeComparator extends Object implements IRangeComparator, Iterable<TextNode>
A comparator that generates a DOM tree of sorts from handling SAX events. Then it can be used to compute the difference between DOM trees and mark elements accordingly.
-
-
Constructor Summary
Constructors Constructor Description TextNodeComparator(DomTree tree, Locale locale)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
expandWhiteSpace()
BodyNode
getBodyNode()
long
getChangedID()
long
getDeletedID()
List<Modification>
getLastModified()
long
getNewID()
int
getRangeCount()
Returns the number of comparable entities.TextNode
getTextNode(int i)
void
handlePossibleChangedPart(int leftstart, int leftend, int rightstart, int rightend, TextNodeComparator leftComparator)
Iterator<TextNode>
iterator()
void
markAsDeleted(int start, int end, TextNodeComparator oldComp, int before, int after)
Marks the given range as deleted.void
markAsDeleted(int start, int end, TextNodeComparator oldComp, int before, int after, ModificationType outputFormat)
Marks the given range as deleted.void
markAsNew(int start, int end)
Marks the given range as new.void
markAsNew(int start, int end, ModificationType outputFormat)
Marks the given range as new.boolean
rangesEqual(int i1, IRangeComparator rangeComp, int i2)
Returns whether the comparable entity given by the first index matches an entity specified by the otherIRangeComparator
and index.void
setLastModified(List<Modification> aLastModified)
void
setStartChangedID(long aChangedID)
Used for combining multiple comparators in order to create a single output document.void
setStartDeletedID(long aDeletedID)
Used for combining multiple comparators in order to create a single output document.void
setStartNewID(long aNewID)
Used for combining multiple comparators in order to create a single output document.boolean
skipRangeComparison(int arg0, int arg1, IRangeComparator arg2)
Returns whether a comparison should be skipped because it would be too costly (or lengthy).-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
getBodyNode
public BodyNode getBodyNode()
-
getRangeCount
public int getRangeCount()
Description copied from interface:IRangeComparator
Returns the number of comparable entities.- Specified by:
getRangeCount
in interfaceIRangeComparator
- Returns:
- the number of comparable entities
-
getTextNode
public TextNode getTextNode(int i)
-
markAsNew
public void markAsNew(int start, int end, ModificationType outputFormat)
Marks the given range as new. In the output, the range will be formatted as specified by the anOutputFormat parameter.- Parameters:
start
-end
-outputFormat
- specifies how this range shall be formatted in the output
-
markAsNew
public void markAsNew(int start, int end)
Marks the given range as new. In the output, the range will be formatted as "added".- Parameters:
start
-end
-
-
rangesEqual
public boolean rangesEqual(int i1, IRangeComparator rangeComp, int i2)
Description copied from interface:IRangeComparator
Returns whether the comparable entity given by the first index matches an entity specified by the otherIRangeComparator
and index.- Specified by:
rangesEqual
in interfaceIRangeComparator
- Parameters:
i1
- the index of the comparable entity within thisIRangeComparator
rangeComp
- the IRangeComparator to compare this withi2
- the index of the comparable entity within the otherIRangeComparator
- Returns:
true
if the comparable entities are equal
-
skipRangeComparison
public boolean skipRangeComparison(int arg0, int arg1, IRangeComparator arg2)
Description copied from interface:IRangeComparator
Returns whether a comparison should be skipped because it would be too costly (or lengthy).- Specified by:
skipRangeComparison
in interfaceIRangeComparator
- Parameters:
arg0
- a number on which to base the decision whether to returntrue
orfalse
arg1
- another number on which to base the decision whether to returntrue
orfalse
arg2
- the otherIRangeComparator
to compare with- Returns:
true
to avoid a too lengthy range comparison
-
handlePossibleChangedPart
public void handlePossibleChangedPart(int leftstart, int leftend, int rightstart, int rightend, TextNodeComparator leftComparator)
-
markAsDeleted
public void markAsDeleted(int start, int end, TextNodeComparator oldComp, int before, int after, ModificationType outputFormat)
Marks the given range as deleted. In the output, the range will be formatted as specified by the parameter anOutputFormat.- Parameters:
start
-end
-oldComp
-before
-anOutputFormat
- specifies how this range shall be formatted in the output
-
markAsDeleted
public void markAsDeleted(int start, int end, TextNodeComparator oldComp, int before, int after)
Marks the given range as deleted. In the output, the range will be formatted as "removed".- Parameters:
start
-end
-oldComp
-before
-
-
expandWhiteSpace
public void expandWhiteSpace()
-
setStartDeletedID
public void setStartDeletedID(long aDeletedID)
Used for combining multiple comparators in order to create a single output document. The IDs must be successive along the different comparators.- Parameters:
aDeletedID
-
-
setStartChangedID
public void setStartChangedID(long aChangedID)
Used for combining multiple comparators in order to create a single output document. The IDs must be successive along the different comparators.- Parameters:
aDeletedID
-
-
setStartNewID
public void setStartNewID(long aNewID)
Used for combining multiple comparators in order to create a single output document. The IDs must be successive along the different comparators.- Parameters:
aDeletedID
-
-
getChangedID
public long getChangedID()
-
getDeletedID
public long getDeletedID()
-
getNewID
public long getNewID()
-
getLastModified
public List<Modification> getLastModified()
-
setLastModified
public void setLastModified(List<Modification> aLastModified)
-
-