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>
added
protected int
BOUNDS_TOLERANCE
private java.util.Map<PresentationElement,com.nomagic.magicdraw.tests.common.comparators.DiagramComparatorImpl.Diff>
changed
private java.util.Map<DiagramPresentationElement,DiagramPresentationElement>
diagramMap
private static java.lang.String
IMAGE_FILE_EXTENSION
private boolean
mCompareSymbolProperties
private 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 void
addChange(PresentationElement original, PresentationElement modified, java.lang.String info)
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)
void
clear()
boolean
compareDiagrams(DiagramPresentationElement diagrams1, DiagramPresentationElement diagrams2)
Check if two diagrams are equals by comparing their graphical representations.boolean
compareDiagrams(java.util.Collection<DiagramPresentationElement> diagrams1, java.util.Collection<DiagramPresentationElement> diagrams2)
Compare diagrams in two parallel collections.boolean
compareRecursively(PresentationElement p1, PresentationElement p2)
protected boolean
compareSymbols(PresentationElement pe1, PresentationElement pe2)
Check if two presentation elements bounds are equals.private boolean
compareSymbolsRecursively(java.util.Collection<? extends PresentationElement> symbols1, java.util.Collection<? extends PresentationElement> symbols2)
protected com.nomagic.magicdraw.tests.common.comparators.DiffMarker
createMarker(PresentationElement changed, PresentationElement original, java.awt.Color color, boolean useNames)
Forms shape which draw around element.private static void
ensureProjectActive(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.String
getDiffInfo()
Formats textual information about differences found in compared diagrams.java.lang.String
getPath(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 boolean
isIgnored(PresentationElement element)
protected boolean
isNotCopyBoundsEquals(PresentationElement a1, PresentationElement a2)
private static boolean
isSameElement(Element e1, Element e2)
private static boolean
isSameSymbol(PresentationElement pe1, PresentationElement pe2)
private static void
loadDiagrams(java.util.Collection<DiagramPresentationElement> diagrams)
Loads every diagram in the given collectionprotected void
saveDiffToImage(DiagramPresentationElement diagram, java.io.File file)
void
saveDiffToImageFiles(java.io.File file)
Creates graphical differences on compared diagrams and save it to graphical file.private static void
setActiveProject(DiagramPresentationElement diagramPresentationElement)
Sets diagram's project as active, if it isn't alreadyprivate void
toFullName(PresentationElement pe, java.lang.StringBuilder builder, boolean writePath)
protected java.lang.String
toString(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:
compareDiagrams
in 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:
getDiffInfo
in 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:
saveDiffToImageFiles
in 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()
-
-