Class ScriptHelper


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

      • ScriptHelper

        public ScriptHelper()
    • Method Detail

      • getElementsRecursively

        public static java.util.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 java.util.Collection getElementsRecursively​(java.util.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 java.util.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 java.util.Collection getElementsRecursively​(java.util.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
      • getElementsRecursively

        private static java.util.Collection<Element> getElementsRecursively​(Element owningPackage,
                                                                            Stereotype stereotype,
                                                                            java.util.Set<java.lang.Class> subtypes)
      • getBaseClassesOfStereotype

        private static java.util.Set<java.lang.Class> getBaseClassesOfStereotype​(Stereotype stereotype)
      • 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​(java.util.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
                                                java.util.List<? extends java.lang.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