Class ScriptHelper
java.lang.Object
com.nomagic.magicdraw.modelmetrics.ScriptHelper
Helper methods for calculating metrics.
- Since:
- 13.12.5 (15:19)
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic double
calcAverageForList
(List<? extends Number> items) Calculates average for a list of numbers.static double
calcPercentage
(int all, int covered) Calculates percentage.static Collection
getElementsRecursively
(Element owningPackage) Returns all elements in a package recursively.static Collection
getElementsRecursively
(Element owningPackage, Stereotype stereotype) Returns all elements in a package recursively.static Collection
getElementsRecursively
(Collection<? extends Element> owningPackages) Returns all elements in given packages recursively.static Collection
getElementsRecursively
(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
(Collection<? extends BaseElement> possibleParents, BaseElement possibleChild) Checks if given object is child of any element in a given list of possible parents.
-
Constructor Details
-
ScriptHelper
public ScriptHelper()
-
-
Method Details
-
getElementsRecursively
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
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
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 elementsstereotype
- stereotype of elements to collect.- Returns:
- all owned elements recursively. Given packages are excluded
-
isParentOf
Checks if given object is child of given parent object.- Parameters:
possibleParent
- possible parentpossibleChild
- 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 parentpossibleChild
- possible child- Returns:
- true if possibleChild is child of possibleParent.
-
calcPercentage
public static double calcPercentage(int all, int covered) Calculates percentage.- Parameters:
all
- denominatorcovered
- nominator- Returns:
- percentage value or 0 if denominator <= 0
-
calcAverageForList
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
-