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:
  • Constructor Details

    • Node

      protected Node(Metric metric, String name)
      Creates a new node with the given name.
      Parameters:
      metric - the metric this node belongs to
      name - the human-readable name of the node
  • Method Details

    • getName

      public String getName()
    • getParentName

      public String getParentName()
      Returns the name of the parent element or ROOT 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 all file 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

      public List<Node> getChildren()
    • 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
    • getValues

      public List<Value> getValues()
    • 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 for
      defaultValue - 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 specific Value.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 for
      searchName - 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 method
      searchSignature - 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
    • getAllFileNodes

      public List<FileNode> getAllFileNodes()
    • 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 for
      searchNameHashCode - 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 for
      searchName - 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 for
      searchNameHashCode - 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 specified Node 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 local copy() 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 class Node 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 merged nodes 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 new ContainerNode 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 of nodes that will contain the merged nodes of the trees that are starting at this and the specified Node. In order to merge these two trees, this node and the specified other root node have to use the same Metric 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 the other root node
    • setParasoftToolName

      public void setParasoftToolName(String toolName)
    • getParasoftToolName

      public String getParasoftToolName()
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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
    • filterTreeByModifiedLines

      protected Optional<Node> filterTreeByModifiedLines()
    • 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
    • filterTreeByModifiedFiles

      protected Optional<Node> filterTreeByModifiedFiles()
    • 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
    • filterTreeByIndirectChanges

      protected Optional<Node> filterTreeByIndirectChanges()