java.lang.Object
org.eclipse.tracecompass.incubator.analysis.core.weighted.tree.WeightedTree<T>
Type Parameters:
T - The type of objects in this tree
All Implemented Interfaces:
Comparable<WeightedTree<T>>
Direct Known Subclasses:
AggregatedCallSite, DifferentialWeightedTree

public class WeightedTree<@NonNull T> extends Object implements Comparable<WeightedTree<T>>
A Weighted Tree class to describe hierarchical data with a weight. This class is a concrete class to describe a simple weighted tree, but it is also meant to be extended to support other metrics associated with each tree, apart from the weight. Note that the weight is such that the sum of the weight of the children is smaller or equal to the weight of the parent. Failure to comply to this will result in undefined behaviors when viewing the results. Also, if a child is added to the weighted tree for an object that is already present in the children of this tree, their data will be merged.
Author:
Geneviève Bastien
  • Constructor Details

    • WeightedTree

      public WeightedTree(@NonNull T object)
      Constructor
      Parameters:
      object - The object that goes with this tree.
    • WeightedTree

      public WeightedTree(@NonNull T object, long initialWeight)
      Constructor
      Parameters:
      object - The object that goes with this tree.
      initialWeight - The initial length of this object
  • Method Details

    • getWeight

      public long getWeight()
      Get the weight of this tree. The unit of this weight will depend on the metric it represents.
      Returns:
      The weight of this tree
    • copyOf

      public WeightedTree<T> copyOf()
      Make a copy of this tree, with its statistics. Implementing classes should make sure they copy all fields of the tree, including the statistics. This constructor recursively copies all the children.
      Returns:
      A copy of this weighted tree
    • getObject

      public T getObject()
      Get the object associated with this tree
      Returns:
      The object for this tree
    • getChildren

      public Collection<WeightedTree<T>> getChildren()
      Get the children of this tree
      Returns:
      A collection of children trees
    • addToWeight

      public void addToWeight(long weight)
      Add value to the weight of this tree
      Parameters:
      weight - the amount to add to the length
    • addChild

      public void addChild(WeightedTree<@NonNull T> child)
      Add a child to this tree. If a child for the same object already exists, the data for both children will be merged.
      Parameters:
      child - the child tree to add
    • merge

      public final void merge(WeightedTree<@NonNull T> other)
      Merge a tree's data with this one. This method will modify the current tree. It will first call mergeData(WeightedTree) that needs to be implemented for each implementation of this class. It will then merge the children of both trees by adding the other's children to this one.
      Parameters:
      other - The tree to merge. It has to have the same object as the current tree otherwise it will throw an IllegalArgumentException
    • getStatistics

      public @Nullable IStatistics<?> getStatistics(int metricIndex)
      Get the statistics for a metric at index. If the index < 0, then the metric is the main weight.
      Parameters:
      metricIndex - The index in the list of the metric metric to get. If < 0, then the metric is the weight.
      Returns:
      The statistics for the metric or null if not available
    • getMaxDepth

      public int getMaxDepth()
      Get the maximum depth under and including this tree. A depth of 1 means there is one element under and including this element.
      Returns:
      The maximum depth under and including this tree. The minimal value for the depth is 1.
    • getExtraDataTrees

      public Collection<WeightedTree<@NonNull T>> getExtraDataTrees(int index)
      Get other children of this tree that are not its direct descendants. It can be used for instance to represent extra data, for example kernel statuses for a callstack. A IWeightedTreeProvider will advertise those potential children data that come with this tree, and consumers can then call this method with the index of this extra type, if the tree has more than one extra data set
      Parameters:
      index - The index of this extra children set, as provided by the IWeightedTreeProvider.getExtraDataSets() method.
      Returns:
      The extra children trees
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • compareTo

      public int compareTo(WeightedTree<@NonNull T> o)
      Specified by:
      compareTo in interface Comparable<T>