Class DiagramComparatorImpl

java.lang.Object
com.nomagic.magicdraw.tests.common.comparators.DiagramComparatorImpl
All Implemented Interfaces:
DiagramComparator

@OpenApi public class DiagramComparatorImpl extends Object implements DiagramComparator
Implementation of diagram comparator.
  • Field Details

    • BOUNDS_TOLERANCE

      protected int BOUNDS_TOLERANCE
  • Constructor Details

    • 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 Details

    • clear

      public void clear()
    • compareRecursively

      public boolean compareRecursively(PresentationElement p1, PresentationElement p2)
    • 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 String toString(Rectangle r)
    • compareDiagrams

      public boolean compareDiagrams(Collection<AbstractDiagramPresentationElement> diagrams1, Collection<AbstractDiagramPresentationElement> 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.
    • compareDiagrams

      public boolean compareDiagrams(AbstractDiagramPresentationElement diagrams1, AbstractDiagramPresentationElement 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 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.
    • saveDiffToImage

      protected void saveDiffToImage(AbstractDiagramPresentationElement diagram, File file)
    • getPath

      public 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 ':'.
    • addChange

      protected void addChange(PresentationElement original, PresentationElement modified, String info)
    • getAdded

      public 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 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 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(Map<AbstractDiagramPresentationElement,List<com.nomagic.magicdraw.tests.common.comparators.DiffMarker>> map, AbstractDiagramPresentationElement diagram, com.nomagic.magicdraw.tests.common.comparators.DiffMarker marker)
    • saveDiffToImageFiles

      public void saveDiffToImageFiles(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.
    • createMarker

      protected com.nomagic.magicdraw.tests.common.comparators.DiffMarker createMarker(PresentationElement changed, @CheckForNull PresentationElement original, 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 List<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.