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
public abstract class Node extends Object implements Serializable
A hierarchical decomposition of coverage results.- Author:
- Ullrich Hafner
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addAllChildren(Collection<? extends Node> nodes)
Adds alls given nodes as children to the current node.protected void
addAllValues(Collection<? extends Value> additionalValues)
void
addChild(Node child)
Appends the specified child element to the list of children.void
addValue(Value value)
Appends the specified value to the list of values.List<Value>
aggregateValues()
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.Node
copyNode()
Creates a copy of this instance that has no children and no parent yet.Node
copyTree()
Creates a deep copy of the tree with this as root node.Node
copyTree(Node copiedParent)
Creates a deep copy of the tree with the specifiedNode
as root.boolean
equals(Object o)
Node
filterByIndirectChanges()
Creates a new coverage tree that shows indirect coverage changes.Node
filterByModifiedFiles()
Creates a new coverage tree that represents the modified files coverage.Node
filterByModifiedLines()
Creates a new coverage tree that represents the modified lines coverage.protected Optional<Node>
filterTreeByIndirectChanges()
protected Optional<Node>
filterTreeByModifiedFiles()
protected Optional<Node>
filterTreeByModifiedLines()
Optional<Node>
find(Metric searchMetric, String searchName)
Finds the metric with the given name starting from this node.Optional<Node>
findByHashCode(Metric searchMetric, int searchNameHashCode)
Finds the metric with the given hash code starting from this node.Optional<ClassNode>
findClass(String searchName)
Searches for a class within this node that has the given name.Optional<FileNode>
findFile(String searchName)
Searches for a file within this node that has the given name.Optional<MethodNode>
findMethod(String searchName, String searchSignature)
Searches for a method within this node that has the given name and signature.Optional<PackageNode>
findPackage(String searchName)
Searches for a package within this node that has the given name.List<Node>
getAll(Metric searchMetric)
Returns recursively all nodes for the specified metric type.List<FileNode>
getAllFileNodes()
List<MethodNode>
getAllMethodNodes()
List<Node>
getChildren()
Set<String>
getFiles()
Returns the file names that are contained within the subtree of this node.Metric
getMetric()
NavigableSet<Metric>
getMetrics()
Returns the available metrics for the whole tree starting with this node.String
getName()
String
getParasoftToolName()
Node
getParent()
Returns the parent node.String
getParentName()
Returns the name of the parent element orROOT
if there is no such element.Set<String>
getSourceFolders()
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.Optional<Value>
getValue(Metric searchMetric)
Returns the value for the specified metric.NavigableSet<Metric>
getValueMetrics()
Returns the available metrics for the whole tree starting with this node.List<Value>
getValues()
boolean
hasChildren()
Returns whether this node has children or not.int
hashCode()
boolean
hasModifiedLines()
Checks whether code any changes have been detected no matter if the code coverage is affected or not.boolean
hasParent()
Returns whether this node has a parent node.boolean
isEmpty()
boolean
isRoot()
Returns whether this node is the root of the tree.boolean
matches(Metric searchMetric, int searchNameHashCode)
Returns whether this node matches the specified metric and name.boolean
matches(Metric searchMetric, String searchName)
Returns whether this node matches the specified metric and name.Node
merge(Node other)
static Node
merge(List<? extends Node> nodes)
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)
String
toString()
-
-
-
Method Detail
-
getName
public String getName()
-
getParentName
public String getParentName()
Returns the name of the parent element orROOT
if there is no such element.- Returns:
- the name of the parent element
-
getMetric
public Metric getMetric()
-
getMetrics
public NavigableSet<Metric> getMetrics()
Returns the available metrics for the whole tree starting with this node.- Returns:
- the elements in this tree
-
containsMetric
public boolean containsMetric(Metric searchMetric)
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
public Set<String> 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
-
addChild
public void addChild(Node child)
Appends the specified child element to the list of children.- Parameters:
child
- the child to add
-
removeChild
protected void removeChild(Node child)
-
addAllChildren
public void addAllChildren(Collection<? extends Node> nodes)
Adds alls given nodes as children to the current node.- Parameters:
nodes
- nodes to add
-
getParent
public Node 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
-
addValue
public void addValue(Value value)
Appends the specified value to the list of values.- Parameters:
value
- the value to add
-
replaceValue
public void replaceValue(Value value)
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
protected void addAllValues(Collection<? extends Value> additionalValues)
-
getValueMetrics
public NavigableSet<Metric> getValueMetrics()
Returns the available metrics for the whole tree starting with this node.- Returns:
- the elements in this tree
-
getValue
public Optional<Value> getValue(Metric searchMetric)
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
public <T extends Value> T getTypedValue(Metric searchMetric, T defaultValue)
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
public List<Value> aggregateValues()
Aggregates all values that are part of the subtree that is spanned by this node.- Returns:
- aggregation of values below this tree
-
computeDelta
public 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. 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
public List<Node> getAll(Metric searchMetric)
Returns recursively all nodes for the specified metric type.- Parameters:
searchMetric
- the metric to look for- Returns:
- all nodes for the given metric
-
find
public Optional<Node> find(Metric searchMetric, String searchName)
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
public Optional<PackageNode> findPackage(String searchName)
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
public Optional<FileNode> findFile(String searchName)
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
public Optional<ClassNode> findClass(String searchName)
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
public Optional<MethodNode> findMethod(String searchName, String searchSignature)
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
public Set<String> getFiles()
Returns the file names that are contained within the subtree of this node.- Returns:
- the file names
-
getAllMethodNodes
public List<MethodNode> getAllMethodNodes()
-
findByHashCode
public Optional<Node> findByHashCode(Metric searchMetric, int searchNameHashCode)
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
public boolean matches(Metric searchMetric, String searchName)
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
public boolean matches(Metric searchMetric, int searchNameHashCode)
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
public Node copyTree()
Creates a deep copy of the tree with this as root node.- Returns:
- the root node of the copied tree
-
copyTree
public Node copyTree(@CheckForNull Node copiedParent)
Creates a deep copy of the tree with the specifiedNode
as root.- Parameters:
copiedParent
- The root node- Returns:
- the copied tree
-
copyNode
public final Node 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
public abstract 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
public static Node merge(List<? extends Node> nodes)
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
public Node merge(Node other)
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
public void setParasoftToolName(String toolName)
-
getParasoftToolName
public String getParasoftToolName()
-
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
public Node 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
-
filterByModifiedFiles
public Node 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
-
filterByIndirectChanges
public Node 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
-
-