Package eu.maveniverse.domtrip
Class DiffResult
- java.lang.Object
-
- eu.maveniverse.domtrip.DiffResult
-
public class DiffResult extends java.lang.ObjectThe result of comparing two XML documents, containing all detected changes.Provides methods to filter changes by type (semantic vs. formatting-only) or by path, and to check whether any changes were detected.
Example:
DiffResult diff = XmlDiff.diff(before, after); // Semantic changes only (ignore whitespace/formatting) List<XmlChange> semantic = diff.semanticChanges(); // Formatting-only changes List<XmlChange> formatting = diff.formattingChanges(); // Changes at a specific path List<XmlChange> depChanges = diff.changesUnder("/project/dependencies");
-
-
Constructor Summary
Constructors Constructor Description DiffResult(java.util.List<XmlChange> changes)Creates a new DiffResult with the given changes.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<XmlChange>changes()Returns all changes.java.util.List<XmlChange>changesFor(XPathExpression xpath, Document doc)Returns changes affecting elements that match the given compiled XPath expression in the specified document.java.util.List<XmlChange>changesFor(java.lang.String xpath, Document doc)Returns changes affecting elements that match the given XPath expression in the specified document.java.util.List<XmlChange>changesUnder(java.lang.String path)Returns changes under the specified path prefix.java.util.List<XmlChange>formattingChanges()Returns only formatting changes that do not affect meaning.booleanhasAttributeOrderChanges()Returnstrueif any changes affecting attribute order were detected.booleanhasChanges()Returnstrueif any changes were detected.booleanhasFormattingChanges()Returnstrueif any formatting changes were detected.booleanhasSemanticChanges()Returnstrueif any semantic changes were detected.java.util.List<XmlChange>semanticChanges()Returns only semantic changes that affect the meaning of the XML.java.lang.StringtoString()
-
-
-
Constructor Detail
-
DiffResult
public DiffResult(java.util.List<XmlChange> changes)
Creates a new DiffResult with the given changes.- Parameters:
changes- the list of changes
-
-
Method Detail
-
changes
public java.util.List<XmlChange> changes()
Returns all changes.- Returns:
- an unmodifiable list of all changes
-
semanticChanges
public java.util.List<XmlChange> semanticChanges()
Returns only semantic changes that affect the meaning of the XML.- Returns:
- the list of semantic changes
-
formattingChanges
public java.util.List<XmlChange> formattingChanges()
Returns only formatting changes that do not affect meaning.- Returns:
- the list of formatting-only changes
-
changesUnder
public java.util.List<XmlChange> changesUnder(java.lang.String path)
Returns changes under the specified path prefix.This method uses boundary-aware matching: a change path must either equal the given path exactly, or start with the path followed by
/or/@. For example, path/project/namewill NOT match a change at/project/namespace.- Parameters:
path- the path prefix to filter by- Returns:
- the list of changes under the given path
-
hasChanges
public boolean hasChanges()
Returnstrueif any changes were detected.- Returns:
trueif there are changes
-
changesFor
public java.util.List<XmlChange> changesFor(java.lang.String xpath, Document doc)
Returns changes affecting elements that match the given XPath expression in the specified document. This enables rich filtering likediff.changesFor("//dependency[scope='test']", afterDoc).- Parameters:
xpath- the XPath expression to match elementsdoc- the document to evaluate the expression against- Returns:
- the list of changes at or under matching elements
- Since:
- 1.3.0
-
changesFor
public java.util.List<XmlChange> changesFor(XPathExpression xpath, Document doc)
Returns changes affecting elements that match the given compiled XPath expression in the specified document.- Parameters:
xpath- the compiled XPath expression to match elementsdoc- the document to evaluate the expression against- Returns:
- the list of changes at or under matching elements
- Since:
- 1.3.0
-
hasSemanticChanges
public boolean hasSemanticChanges()
Returnstrueif any semantic changes were detected.- Returns:
trueif there are semantic changes
-
hasFormattingChanges
public boolean hasFormattingChanges()
Returnstrueif any formatting changes were detected.- Returns:
trueif there are formatting-only changes
-
hasAttributeOrderChanges
public boolean hasAttributeOrderChanges()
Returnstrueif any changes affecting attribute order were detected.Attribute order is not considered a semantic difference in XML, but in many real-world use cases (configuration files, generated build metadata etc.) it is desirable to detect reordering separately from other formatting-only changes like whitespace or quote styles.
This method reports
truewhen the diff contains anChangeType.ATTRIBUTE_MOVEDchange.- Returns:
trueif there are attribute order changes- Since:
- 1.5.0
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-