Class WeightedTree<T>
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
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 Summary
ConstructorDescriptionWeightedTree
(@NonNull T object) ConstructorWeightedTree
(@NonNull T object, long initialWeight) Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoid
addChild
(WeightedTree<@NonNull T> child) Add a child to this tree.void
addToWeight
(long weight) Add value to the weight of this treeint
compareTo
(WeightedTree<@NonNull T> o) copyOf()
Make a copy of this tree, with its statistics.Get the children of this treeCollection<WeightedTree<@NonNull T>>
getExtraDataTrees
(int index) Get other children of this tree that are not its direct descendants.int
Get the maximum depth under and including this tree.Get the object associated with this tree@Nullable IStatistics<?>
getStatistics
(int metricIndex) Get the statistics for a metric at index.long
Get the weight of this tree.final void
merge
(WeightedTree<@NonNull T> other) Merge a tree's data with this one.toString()
-
Constructor Details
-
WeightedTree
Constructor- Parameters:
object
- The object that goes with this tree.
-
WeightedTree
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
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
Get the object associated with this tree- Returns:
- The object for this tree
-
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
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
Merge a tree's data with this one. This method will modify the current tree. It will first callmergeData(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 anIllegalArgumentException
-
getStatistics
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
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. AIWeightedTreeProvider
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 theIWeightedTreeProvider.getExtraDataSets()
method.- Returns:
- The extra children trees
-
toString
-
compareTo
- Specified by:
compareTo
in interfaceComparable<T>
-