Class ScriptHelper

java.lang.Object
com.nomagic.magicdraw.modelmetrics.ScriptHelper

@OpenApiAll public class ScriptHelper extends Object
Helper methods for calculating metrics.
Since:
13.12.5 (15:19)
  • Constructor Details

    • ScriptHelper

      public ScriptHelper()
  • Method Details

    • getElementsRecursively

      public static Collection getElementsRecursively(Element owningPackage)
      Returns all elements in a package recursively.
      Parameters:
      owningPackage - package to collect the elements.
      Returns:
      all owned elements recursively. The input owningPackage is excluded.
    • getElementsRecursively

      public static Collection getElementsRecursively(Collection<? extends Element> owningPackages)
      Returns all elements in given packages recursively.
      Parameters:
      owningPackages - collection of packages to collect the elements
      Returns:
      all owned elements recursively. Given packages are excluded
    • getElementsRecursively

      public static Collection getElementsRecursively(Element owningPackage, Stereotype stereotype)
      Returns all elements in a package recursively.
      Parameters:
      owningPackage - package to collect the elements.
      stereotype - stereotype of elements to collect.
      Returns:
      all owned elements recursively. The input owningPackage is excluded.
    • getElementsRecursively

      public static Collection getElementsRecursively(Collection<? extends Element> owningPackages, Stereotype stereotype)
      Returns all elements in given packages recursively.
      Parameters:
      owningPackages - collection of packages to collect the elements
      stereotype - stereotype of elements to collect.
      Returns:
      all owned elements recursively. Given packages are excluded
    • isParentOf

      public static boolean isParentOf(BaseElement possibleParent, BaseElement possibleChild)
      Checks if given object is child of given parent object.
      Parameters:
      possibleParent - possible parent
      possibleChild - possible child
      Returns:
      true if possibleChild is child of possibleParent.
    • isParentOf

      public static boolean isParentOf(Collection<? extends BaseElement> possibleParents, BaseElement possibleChild)
      Checks if given object is child of any element in a given list of possible parents.
      Parameters:
      possibleParents - possible parent
      possibleChild - possible child
      Returns:
      true if possibleChild is child of possibleParent.
    • calcPercentage

      public static double calcPercentage(int all, int covered)
      Calculates percentage.
      Parameters:
      all - denominator
      covered - nominator
      Returns:
      percentage value or 0 if denominator <= 0
    • calcAverageForList

      public static double calcAverageForList(@CheckForNull List<? extends Number> items)
      Calculates average for a list of numbers.
      Parameters:
      items - list of numbers
      Returns:
      average value for the given list of numbers or 0 by default