Class StructuralVisualDiff
- java.lang.Object
-
- com.crawljax.stateabstractions.hybrid.structuralvisualdiff.StructuralVisualDiff
-
public class StructuralVisualDiff extends Object
-
-
Field Summary
Fields Modifier and Type Field Description private Set<String>addedNodesprivate longcomputationTimeprivate static org.slf4j.LoggerLOGGERprivate Set<String>modifiedNodesprivate Set<String>movedNodesprivate DocumentnewDocumentprivate StateVertexForElementsWithVisualInfonewVertexprivate Map<String,String>nodeMappingsprivate DocumentoldDocumentprivate StateVertexForElementsWithVisualInfooldVertexprivate Set<String>removedNodesprivate floatstructuralDistance
-
Constructor Summary
Constructors Modifier Constructor Description privateStructuralVisualDiff(StateVertexForElementsWithVisualInfo oldVertex, StateVertexForElementsWithVisualInfo newVertex)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StructuralVisualDiffcalculate(StateVertexForElementsWithVisualInfo oldVertex, StateVertexForElementsWithVisualInfo newVertex)Returns a new instance of StructuralVisualDiff which includes the changes across the two given statesvoidcomputeDiff()private voiddetectNodeModifications()Set<String>getAddedNodes()private AptedNode<StringNodeData>getAPTEDTreeFromDocument(Node node)longgetComputationTime()Map<String,String>getMappedNodes()Set<String>getModifiedNodes()Set<String>getMovedNodes()DOMElementWithVisualInfogetNewElementWithVisualInfo(String xpath)Given an XPath for a node, this method returnsDOMElementWithVisualInfoof the node in the new document.private StringgetNodeStringRepresentation(Node node)DOMElementWithVisualInfogetOldElementWithVisualInfo(String xpath)Given an XPath for a node, this method returnsDOMElementWithVisualInfoof the node in the old document.Set<String>getRemovedNodes()floatgetStructuralDistance()private voidpopulatePostorder(List<Node> postorderList, Node node)voidserializeDiff(String pathToJSONFile)booleanstatesAreIdentical()Tells whether two states are identical after performing the analysis.StringtoString()
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
oldVertex
private final StateVertexForElementsWithVisualInfo oldVertex
-
newVertex
private final StateVertexForElementsWithVisualInfo newVertex
-
structuralDistance
private float structuralDistance
-
computationTime
private long computationTime
-
oldDocument
private transient Document oldDocument
-
newDocument
private transient Document newDocument
-
-
Constructor Detail
-
StructuralVisualDiff
private StructuralVisualDiff(StateVertexForElementsWithVisualInfo oldVertex, StateVertexForElementsWithVisualInfo newVertex)
-
-
Method Detail
-
calculate
public static StructuralVisualDiff calculate(StateVertexForElementsWithVisualInfo oldVertex, StateVertexForElementsWithVisualInfo newVertex)
Returns a new instance of StructuralVisualDiff which includes the changes across the two given states- Parameters:
oldVertex- Old state. Should be of typeStateVertexForElementsWithVisualInfosince it relies on the visual information recorded in the previous run of the crawlernewVertex- New state to which we are comparing the old state- Returns:
-
computeDiff
public void computeDiff()
-
detectNodeModifications
private void detectNodeModifications()
-
getAPTEDTreeFromDocument
private AptedNode<StringNodeData> getAPTEDTreeFromDocument(Node node)
-
getStructuralDistance
public float getStructuralDistance()
- Returns:
- The distance between the two DOM states based on the APTED algorithm and string cost model
-
getMappedNodes
public Map<String,String> getMappedNodes()
- Returns:
- Nodes mapped across the two DOMs
-
getRemovedNodes
public Set<String> getRemovedNodes()
- Returns:
- Nodes that have been removed from the old DOM
-
getMovedNodes
public Set<String> getMovedNodes()
- Returns:
- Nodes (from the old state) that are mapped across the two states but are moved
-
getModifiedNodes
public Set<String> getModifiedNodes()
- Returns:
- Nodes that are modified (visually or textually) from the old state
-
getComputationTime
public long getComputationTime()
- Returns:
- Time took to compute the edit distance in the APTED algorithm
-
statesAreIdentical
public boolean statesAreIdentical()
Tells whether two states are identical after performing the analysis. Three things are checked: (1) there is no modified node (visually or textually), (2) there is no moved node, and (3) the distance between the two DOMs' structures is zero (i.e., there is no added/removed nodes and all nodes are mapped without any differences in tag names)- Returns:
- True if the states are identical
-
getOldElementWithVisualInfo
public DOMElementWithVisualInfo getOldElementWithVisualInfo(String xpath)
Given an XPath for a node, this method returnsDOMElementWithVisualInfoof the node in the old document. The XPath should be from the old document.- Parameters:
xpath- of the node- Returns:
- The node of type
DOMElementWithVisualInfo.nullif the node does not exist.
-
getNewElementWithVisualInfo
public DOMElementWithVisualInfo getNewElementWithVisualInfo(String xpath)
Given an XPath for a node, this method returnsDOMElementWithVisualInfoof the node in the new document. The XPath should be from the new document.- Parameters:
xpath- of the node- Returns:
- The node of type
DOMElementWithVisualInfo.nullif the node does not exist.
-
serializeDiff
public void serializeDiff(String pathToJSONFile) throws IOException
- Throws:
IOException
-
-