Class Node
java.lang.Object
com.parasoft.findings.jenkins.coverage.model.Node
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
ClassNode
,ContainerNode
,FileNode
,MethodNode
,ModuleNode
,PackageNode
A hierarchical decomposition of coverage results.
- Author:
- Ullrich Hafner
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addAllChildren
(Collection<? extends Node> nodes) Adds alls given nodes as children to the current node.protected void
addAllValues
(Collection<? extends Value> additionalValues) void
Appends the specified child element to the list of children.void
Appends the specified value to the list of values.Aggregates all values that are part of the subtree that is spanned by this node.NavigableMap<Metric,
org.apache.commons.lang3.math.Fraction> computeDelta
(Node reference) Computes the delta of all metrics between this node and the specified reference node as fractions.boolean
containsMetric
(Metric searchMetric) Returns whether results for the specified metric are available within the tree spanned by this node.abstract Node
copy()
Creates a copy of this instance that has no children and no parent yet.final Node
copyNode()
Creates a copy of this instance that has no children and no parent yet.copyTree()
Creates a deep copy of the tree with this as root node.Creates a deep copy of the tree with the specifiedNode
as root.boolean
Creates a new coverage tree that shows indirect coverage changes.Creates a new coverage tree that represents the modified files coverage.Creates a new coverage tree that represents the modified lines coverage.Finds the metric with the given name starting from this node.findByHashCode
(Metric searchMetric, int searchNameHashCode) Finds the metric with the given hash code starting from this node.Searches for a class within this node that has the given name.Searches for a file within this node that has the given name.findMethod
(String searchName, String searchSignature) Searches for a method within this node that has the given name and signature.findPackage
(String searchName) Searches for a package within this node that has the given name.Returns recursively all nodes for the specified metric type.getFiles()
Returns the file names that are contained within the subtree of this node.Returns the available metrics for the whole tree starting with this node.getName()
Returns the parent node.Returns the name of the parent element orROOT
if there is no such element.Returns a collection of source folders that contain the source code files of allfile nodes
.<T extends Value>
TgetTypedValue
(Metric searchMetric, T defaultValue) Returns the value for the specified metric.Returns the value for the specified metric.Returns the available metrics for the whole tree starting with this node.boolean
Returns whether this node has children or not.int
hashCode()
boolean
Checks whether code any changes have been detected no matter if the code coverage is affected or not.boolean
Returns whether this node has a parent node.boolean
isEmpty()
boolean
isRoot()
Returns whether this node is the root of the tree.boolean
Returns whether this node matches the specified metric and name.boolean
Returns whether this node matches the specified metric and name.static Node
Creates a new tree of mergednodes
if all nodes have the same name and metric.protected void
removeChild
(Node child) void
replaceValue
(Value value) Replaces an existing value of the specified metric with the specified value.void
setParasoftToolName
(String toolName) toString()
-
Constructor Details
-
Node
Creates a new node with the given name.- Parameters:
metric
- the metric this node belongs toname
- the human-readable name of the node
-
-
Method Details
-
getName
-
getParentName
Returns the name of the parent element orROOT
if there is no such element.- Returns:
- the name of the parent element
-
getMetric
-
getMetrics
Returns the available metrics for the whole tree starting with this node.- Returns:
- the elements in this tree
-
containsMetric
Returns whether results for the specified metric are available within the tree spanned by this node.- Parameters:
searchMetric
- the metric to look for- Returns:
true
if results for the specified metric are available,false
otherwise
-
getSourceFolders
Returns a collection of source folders that contain the source code files of allfile nodes
.- Returns:
- a collection of source folders
-
hasChildren
public boolean hasChildren()Returns whether this node has children or not.- Returns:
true
if this node has children,false
otherwise
-
getChildren
-
addChild
Appends the specified child element to the list of children.- Parameters:
child
- the child to add
-
removeChild
-
addAllChildren
Adds alls given nodes as children to the current node.- Parameters:
nodes
- nodes to add
-
getParent
Returns the parent node.- Returns:
- the parent, if existent
- Throws:
NoSuchElementException
- if no parent exists
-
isRoot
public boolean isRoot()Returns whether this node is the root of the tree.- Returns:
true
if this node is the root of the tree,false
otherwise
-
hasParent
public boolean hasParent()Returns whether this node has a parent node.- Returns:
true
if this node has a parent node,false
if it is the root of the hierarchy
-
getValues
-
addValue
Appends the specified value to the list of values.- Parameters:
value
- the value to add
-
replaceValue
Replaces an existing value of the specified metric with the specified value. If no value with the specified metric exists, then the value is added.- Parameters:
value
- the value to replace
-
addAllValues
-
getValueMetrics
Returns the available metrics for the whole tree starting with this node.- Returns:
- the elements in this tree
-
getValue
Returns the value for the specified metric. The value is aggregated for the whole subtree this node is the root of.- Parameters:
searchMetric
- the metric to get the value for- Returns:
- coverage ratio
-
getTypedValue
Returns the value for the specified metric. The value is aggregated for the whole subtree this node is the root of.- Type Parameters:
T
- the concrete type of the value- Parameters:
searchMetric
- the metric to get the value fordefaultValue
- the default value to return if no value has been defined for the specified metric- Returns:
- coverage ratio
-
aggregateValues
Aggregates all values that are part of the subtree that is spanned by this node.- Returns:
- aggregation of values below this tree
-
computeDelta
Computes the delta of all metrics between this node and the specified reference node as fractions. Each delta value is computed by the value specificValue.delta(Value)
method. If the reference node does not contain a specific metric, then no delta is computed and the metric is omitted in the result map.- Parameters:
reference
- the reference node- Returns:
- the delta coverage for each available metric as fraction
-
getAll
Returns recursively all nodes for the specified metric type.- Parameters:
searchMetric
- the metric to look for- Returns:
- all nodes for the given metric
-
find
Finds the metric with the given name starting from this node.- Parameters:
searchMetric
- the metric to search forsearchName
- the name of the node- Returns:
- the result if found
-
findPackage
Searches for a package within this node that has the given name.- Parameters:
searchName
- the name of the package- Returns:
- the first matching package or an empty result, if no such package exists
-
findFile
Searches for a file within this node that has the given name.- Parameters:
searchName
- the name of the file- Returns:
- the first matching file or an empty result, if no such file exists
-
findClass
Searches for a class within this node that has the given name.- Parameters:
searchName
- the name of the class- Returns:
- the first matching class or an empty result, if no such class exists
-
findMethod
Searches for a method within this node that has the given name and signature.- Parameters:
searchName
- the name of the methodsearchSignature
- the signature of the method- Returns:
- the first matching method or an empty result, if no such method exists
-
getFiles
Returns the file names that are contained within the subtree of this node.- Returns:
- the file names
-
getAllFileNodes
-
getAllMethodNodes
-
findByHashCode
Finds the metric with the given hash code starting from this node.- Parameters:
searchMetric
- the metric to search forsearchNameHashCode
- the hash code of the node name- Returns:
- the result if found
-
matches
Returns whether this node matches the specified metric and name.- Parameters:
searchMetric
- the metric to search forsearchName
- the name of the node- Returns:
- the result if found
-
matches
Returns whether this node matches the specified metric and name.- Parameters:
searchMetric
- the metric to search forsearchNameHashCode
- the hash code of the node name- Returns:
- the result if found
-
copyTree
Creates a deep copy of the tree with this as root node.- Returns:
- the root node of the copied tree
-
copyTree
Creates a deep copy of the tree with the specifiedNode
as root.- Parameters:
copiedParent
- The root node- Returns:
- the copied tree
-
copyNode
Creates a copy of this instance that has no children and no parent yet. This method will copy all stored values of this node. This method delegates to the instance localcopy()
method to copy all properties introduced by subclasses.- Returns:
- the copied node
-
copy
Creates a copy of this instance that has no children and no parent yet. Node properties from the parent classNode
must not be copied. All other immutable properties need to be copied one by one.- Returns:
- the copied node
-
merge
Creates a new tree of mergednodes
if all nodes have the same name and metric. If the nodes have different names or metrics, then these nodes will be attached to a newContainerNode
node.- Parameters:
nodes
- the nodes to merge- Returns:
- a new tree with the merged
nodes
-
merge
Creates a new tree ofnodes
that will contain the merged nodes of the trees that are starting at this and the specifiedNode
. In order to merge these two trees, this node and the specifiedother
root node have to use the sameMetric
and name.- Parameters:
other
- the other tree to merge (represented by the root node)- Returns:
- a new tree with the merged
nodes
- Throws:
IllegalArgumentException
- if this root node is not compatible to theother
root node
-
setParasoftToolName
-
getParasoftToolName
-
equals
-
hashCode
public int hashCode() -
toString
-
isEmpty
public boolean isEmpty() -
hasModifiedLines
public boolean hasModifiedLines()Checks whether code any changes have been detected no matter if the code coverage is affected or not.- Returns:
true
whether code changes have been detected
-
filterByModifiedLines
Creates a new coverage tree that represents the modified lines coverage. This new tree will contain only those elements that contain modified lines.- Returns:
- the filtered tree
-
filterTreeByModifiedLines
-
filterByModifiedFiles
Creates a new coverage tree that represents the modified files coverage. This new tree will contain only those elements that have modified files. The difference against the modified line coverage is that the modified files coverage tree represents the total coverage of all files with coverage relevant changes, not only the coverage of the modified lines.- Returns:
- the filtered tree
-
filterTreeByModifiedFiles
-
filterByIndirectChanges
Creates a new coverage tree that shows indirect coverage changes. This new tree will contain only those elements that have elements with a modified coverage but with no modified code lines.- Returns:
- the filtered tree
-
filterTreeByIndirectChanges
-