Class DiagramComparatorImpl

  • All Implemented Interfaces:
    DiagramComparator

    @OpenApi
    public class DiagramComparatorImpl
    extends java.lang.Object
    implements DiagramComparator
    Implementation of diagram comparator.
    • 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()
      • compareSymbolsRecursively

        private boolean compareSymbolsRecursively​(java.util.Collection<? extends PresentationElement> symbols1,
                                                  java.util.Collection<? extends PresentationElement> symbols2)
      • 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)
      • 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 interface DiagramComparator
        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 interface DiagramComparator
        Returns:
        String information about differences found in compared diagrams or empty String if no differences found.
      • 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)
      • 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 interface DiagramComparator
        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 element
        original - original element
        color - 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.