Class DiagramComparatorImpl
- java.lang.Object
-
- com.nomagic.magicdraw.tests.common.comparators.DiagramComparatorImpl
-
- All Implemented Interfaces:
DiagramComparator
@OpenApi public class DiagramComparatorImpl extends java.lang.Object implements DiagramComparator
Implementation of diagram comparator.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Set<PresentationElement>addedprotected intBOUNDS_TOLERANCEprivate java.util.Map<PresentationElement,com.nomagic.magicdraw.tests.common.comparators.DiagramComparatorImpl.Diff>changedprivate java.util.Map<DiagramPresentationElement,DiagramPresentationElement>diagramMapprivate static java.lang.StringIMAGE_FILE_EXTENSIONprivate booleanmCompareSymbolPropertiesprivate java.util.Set<PresentationElement>removed
-
Constructor Summary
Constructors Constructor Description DiagramComparatorImpl()DiagramComparatorImpl(boolean compareSymbolProperties)DiagramComparatorImpl(int boundsTolerance, boolean compareSymbolProperties)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddChange(PresentationElement original, PresentationElement modified, java.lang.String info)protected static voidaddMarker(java.util.Map<DiagramPresentationElement,java.util.List<com.nomagic.magicdraw.tests.common.comparators.DiffMarker>> map, DiagramPresentationElement diagram, com.nomagic.magicdraw.tests.common.comparators.DiffMarker marker)voidclear()booleancompareDiagrams(DiagramPresentationElement diagrams1, DiagramPresentationElement diagrams2)Check if two diagrams are equals by comparing their graphical representations.booleancompareDiagrams(java.util.Collection<DiagramPresentationElement> diagrams1, java.util.Collection<DiagramPresentationElement> diagrams2)Compare diagrams in two parallel collections.booleancompareRecursively(PresentationElement p1, PresentationElement p2)protected booleancompareSymbols(PresentationElement pe1, PresentationElement pe2)Check if two presentation elements bounds are equals.private booleancompareSymbolsRecursively(java.util.Collection<? extends PresentationElement> symbols1, java.util.Collection<? extends PresentationElement> symbols2)protected com.nomagic.magicdraw.tests.common.comparators.DiffMarkercreateMarker(PresentationElement changed, PresentationElement original, java.awt.Color color, boolean useNames)Forms shape which draw around element.private static voidensureProjectActive(Project project, java.lang.Runnable runnable)java.util.Set<PresentationElement>getAdded()Presentation elements which are added to second compared diagram and do not exist on the first compared diagram.java.util.Map<PresentationElement,com.nomagic.magicdraw.tests.common.comparators.DiagramComparatorImpl.Diff>getChanged()Changed presentation elements and their difference information found in compared diagrams.protected java.util.Map<DiagramPresentationElement,DiagramPresentationElement>getDiagramsMap()java.lang.StringgetDiffInfo()Formats textual information about differences found in compared diagrams.java.lang.StringgetPath(PresentationElement element)Creates "kind of qualified name" for presentation element in diagram.protected java.util.List<java.awt.Point>getPointsOfShape(PathElement element, int delta)Forms a points around the elements by making a poly line.java.util.Set<PresentationElement>getRemoved()Presentation elements which exist on first compared diagrams and do not exist on the second compared diagram.private static booleanisIgnored(PresentationElement element)protected booleanisNotCopyBoundsEquals(PresentationElement a1, PresentationElement a2)private static booleanisSameElement(Element e1, Element e2)private static booleanisSameSymbol(PresentationElement pe1, PresentationElement pe2)private static voidloadDiagrams(java.util.Collection<DiagramPresentationElement> diagrams)Loads every diagram in the given collectionprotected voidsaveDiffToImage(DiagramPresentationElement diagram, java.io.File file)voidsaveDiffToImageFiles(java.io.File file)Creates graphical differences on compared diagrams and save it to graphical file.private static voidsetActiveProject(DiagramPresentationElement diagramPresentationElement)Sets diagram's project as active, if it isn't alreadyprivate voidtoFullName(PresentationElement pe, java.lang.StringBuilder builder, boolean writePath)protected java.lang.StringtoString(java.awt.Rectangle r)
-
-
-
Field Detail
-
IMAGE_FILE_EXTENSION
private static final java.lang.String IMAGE_FILE_EXTENSION
- See Also:
- Constant Field Values
-
BOUNDS_TOLERANCE
protected int BOUNDS_TOLERANCE
-
added
private final java.util.Set<PresentationElement> added
-
removed
private final java.util.Set<PresentationElement> removed
-
changed
private final java.util.Map<PresentationElement,com.nomagic.magicdraw.tests.common.comparators.DiagramComparatorImpl.Diff> changed
-
diagramMap
private final java.util.Map<DiagramPresentationElement,DiagramPresentationElement> diagramMap
-
mCompareSymbolProperties
private final boolean mCompareSymbolProperties
-
-
Constructor Detail
-
DiagramComparatorImpl
@OpenApi public DiagramComparatorImpl(int boundsTolerance, boolean compareSymbolProperties)Constructor.- Parameters:
boundsTolerance- tolerance of bounds difference.compareSymbolProperties- if compare symbol properties.
-
DiagramComparatorImpl
public DiagramComparatorImpl()
-
DiagramComparatorImpl
public DiagramComparatorImpl(boolean compareSymbolProperties)
-
-
Method Detail
-
clear
public void clear()
-
compareRecursively
public boolean compareRecursively(PresentationElement p1, PresentationElement p2)
-
compareSymbolsRecursively
private boolean compareSymbolsRecursively(java.util.Collection<? extends PresentationElement> symbols1, java.util.Collection<? extends PresentationElement> symbols2)
-
isIgnored
private static boolean isIgnored(PresentationElement element)
-
isNotCopyBoundsEquals
protected boolean isNotCopyBoundsEquals(PresentationElement a1, PresentationElement a2)
-
compareSymbols
protected boolean compareSymbols(PresentationElement pe1, PresentationElement pe2)
Check if two presentation elements bounds are equals. Two presentations elements are equals if their bounds difference is not more than 1 pixel.- Parameters:
pe1- first presentation element to compare.pe2- second presentation element to compare.- Returns:
- true if compared presentation elements are equals, false otherwise
-
toString
protected java.lang.String toString(java.awt.Rectangle r)
-
isSameSymbol
private static boolean isSameSymbol(PresentationElement pe1, PresentationElement pe2)
-
isSameElement
private static boolean isSameElement(@CheckForNull Element e1, @CheckForNull Element e2)
-
compareDiagrams
public boolean compareDiagrams(java.util.Collection<DiagramPresentationElement> diagrams1, java.util.Collection<DiagramPresentationElement> diagrams2)
Compare diagrams in two parallel collections.- Specified by:
compareDiagramsin interfaceDiagramComparator- Parameters:
diagrams1- first diagram to compare.diagrams2- second diagram to compare.- Returns:
- true if diagrams in both collections are equals, false otherwise.
-
loadDiagrams
private static void loadDiagrams(java.util.Collection<DiagramPresentationElement> diagrams)
Loads every diagram in the given collection- Parameters:
diagrams- diagrams which need to be loaded
-
setActiveProject
private static void setActiveProject(DiagramPresentationElement diagramPresentationElement)
Sets diagram's project as active, if it isn't already- Parameters:
diagramPresentationElement- diagram which project should be active
-
compareDiagrams
public boolean compareDiagrams(DiagramPresentationElement diagrams1, DiagramPresentationElement diagrams2)
Check if two diagrams are equals by comparing their graphical representations.- Parameters:
diagrams1- first diagram to compare.diagrams2- second diagram to compare.- Returns:
- true if compared diagrams graphical presentation is equals.
-
getDiffInfo
public java.lang.String getDiffInfo()
Formats textual information about differences found in compared diagrams. Formatted text contains information about new, removed, and changed symbols in compared diagrams.- Specified by:
getDiffInfoin interfaceDiagramComparator- Returns:
- String information about differences found in compared diagrams or empty String if no differences found.
-
saveDiffToImage
protected void saveDiffToImage(DiagramPresentationElement diagram, java.io.File file)
-
getPath
public java.lang.String getPath(PresentationElement element)
Creates "kind of qualified name" for presentation element in diagram. Such "qualified name" starts with diagram name and all nested presentation elements where given element is nested.- Parameters:
element- presentation element to create "qualified name" for.- Returns:
- String formed from elements parent names separated by semicolon ':'.
-
toFullName
private void toFullName(PresentationElement pe, java.lang.StringBuilder builder, boolean writePath)
-
addChange
protected void addChange(PresentationElement original, PresentationElement modified, java.lang.String info)
-
getAdded
public java.util.Set<PresentationElement> getAdded()
Presentation elements which are added to second compared diagram and do not exist on the first compared diagram.- Returns:
- Set of presentation elements which exist only on second compared diagram.
-
getRemoved
public java.util.Set<PresentationElement> getRemoved()
Presentation elements which exist on first compared diagrams and do not exist on the second compared diagram.- Returns:
- Set of presentation elements which exist only on first compared diagrams.
-
getChanged
public java.util.Map<PresentationElement,com.nomagic.magicdraw.tests.common.comparators.DiagramComparatorImpl.Diff> getChanged()
Changed presentation elements and their difference information found in compared diagrams.- Returns:
- Map with changed presentation elements as keys and their differences specified as Diff values.
-
addMarker
protected static void addMarker(java.util.Map<DiagramPresentationElement,java.util.List<com.nomagic.magicdraw.tests.common.comparators.DiffMarker>> map, DiagramPresentationElement diagram, com.nomagic.magicdraw.tests.common.comparators.DiffMarker marker)
-
saveDiffToImageFiles
public void saveDiffToImageFiles(java.io.File file)
Creates graphical differences on compared diagrams and save it to graphical file. Graphical differences are presented as rectangles on diagrams.- Specified by:
saveDiffToImageFilesin interfaceDiagramComparator- Parameters:
file- graphical file to save compared diagram graphical differences to.
-
ensureProjectActive
private static void ensureProjectActive(Project project, java.lang.Runnable runnable)
-
createMarker
protected com.nomagic.magicdraw.tests.common.comparators.DiffMarker createMarker(PresentationElement changed, @CheckForNull PresentationElement original, java.awt.Color color, boolean useNames)
Forms shape which draw around element.- Parameters:
changed- changes elementoriginal- original elementcolor- of rectangle.useNames- true if needed names for shape, false otherwise.- Returns:
- DiffMarker storing shape, text and color.
-
getPointsOfShape
@CheckForNull protected java.util.List<java.awt.Point> getPointsOfShape(PathElement element, int delta)
Forms a points around the elements by making a poly line.- Parameters:
element- PathElement.delta- pixels from element till formed polyline around element.- Returns:
- List of points going around element.
-
getDiagramsMap
protected java.util.Map<DiagramPresentationElement,DiagramPresentationElement> getDiagramsMap()
-
-