Class ScriptHelper


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

      Constructors 
      Constructor Description
      ScriptHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static double calcAverageForList​(java.util.List<? extends java.lang.Number> items)
      Calculates average for a list of numbers.
      static double calcPercentage​(int all, int covered)
      Calculates percentage.
      static java.util.Collection getElementsRecursively​(Element owningPackage)
      Returns all elements in a package recursively.
      static java.util.Collection getElementsRecursively​(Element owningPackage, Stereotype stereotype)
      Returns all elements in a package recursively.
      static java.util.Collection getElementsRecursively​(java.util.Collection<? extends Element> owningPackages)
      Returns all elements in given packages recursively.
      static java.util.Collection getElementsRecursively​(java.util.Collection<? extends Element> owningPackages, Stereotype stereotype)
      Returns all elements in given packages recursively.
      static boolean isParentOf​(BaseElement possibleParent, BaseElement possibleChild)
      Checks if given object is child of given parent object.
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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
      • 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