1 /*******************************************************************************
2 * Copyright (c) 2016 EfficiOS Inc., Alexandre Montplaisir
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
10 package org
.lttng
.scope
.tmf2
.views
.core
.timegraph
.model
.render
.tree
;
12 import java
.util
.Collections
;
13 import java
.util
.List
;
14 import java
.util
.Objects
;
15 import java
.util
.function
.Predicate
;
17 import org
.eclipse
.jdt
.annotation
.Nullable
;
18 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
20 import com
.google
.common
.base
.MoreObjects
;
21 import com
.google
.common
.collect
.ImmutableList
;
24 * The "tree element" is the unit of a timegraph represented by a single line.
25 * State intervals are aligned with tree elements to represent the states of the
26 * attribute represented by its tree element.
28 * Tree elements can have children, which allows representing them as a tree
29 * structure. At the visualization layer, sub-trees could be allowed to be
30 * expanded/collapsed, which can then change the number of visible tree elements
33 * @author Alexandre Montplaisir
35 public class TimeGraphTreeElement
{
37 /** Non-null reference to a dummy element */
38 public static final TimeGraphTreeElement DUMMY_ELEMENT
= new TimeGraphTreeElement("Dummy", Collections
.emptyList()); //$NON-NLS-1$
40 private final String fName
;
41 private final List
<TimeGraphTreeElement
> fChildElements
;
44 * Constructor, build a tree element by specifying its name and children
48 * The name this tree element should have.
50 * The children tree elements. You can pass an empty list for no
53 public TimeGraphTreeElement(String name
, List
<TimeGraphTreeElement
> children
) {
55 fChildElements
= ImmutableList
.copyOf(children
);
59 * Get the name of this tree element.
61 * @return The element's name
63 public String
getName() {
68 * Get the child elements of this tree element.
70 * @return The child elements
72 public List
<TimeGraphTreeElement
> getChildElements() {
73 return fChildElements
;
77 * Determine if and how this tree element corresponds to a component of a
80 * For example, if this tree element represents "CPU #2", then the predicate
81 * should return true for all trace events belonging to CPU #2.
83 * The method returns null if this tree element does not correspond to a
84 * particular aspect of trace events.
86 * @return The event matching predicate, if there is one
88 public @Nullable Predicate
<ITmfEvent
> getEventMatching() {
89 /* Sub-classes can override */
94 public int hashCode() {
95 return Objects
.hash(fName
, fChildElements
);
99 public boolean equals(@Nullable Object obj
) {
106 if (getClass() != obj
.getClass()) {
109 TimeGraphTreeElement other
= (TimeGraphTreeElement
) obj
;
110 return Objects
.equals(fName
, other
.fName
)
111 && Objects
.equals(fChildElements
, other
.fChildElements
);
115 public String
toString() {
116 return MoreObjects
.toStringHelper(this)
117 .add("fName", fName
) //$NON-NLS-1$
118 .add("fChildElements", fChildElements
.toString()) //$NON-NLS-1$