Import views plugins
[deliverable/tracecompass.git] / tmf / org.lttng.scope.tmf2.views.core / src / org / lttng / scope / tmf2 / views / core / timegraph / model / render / tree / TimeGraphTreeElement.java
1 /*******************************************************************************
2 * Copyright (c) 2016 EfficiOS Inc., Alexandre Montplaisir
3 *
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 *******************************************************************************/
9
10 package org.lttng.scope.tmf2.views.core.timegraph.model.render.tree;
11
12 import java.util.Collections;
13 import java.util.List;
14 import java.util.Objects;
15 import java.util.function.Predicate;
16
17 import org.eclipse.jdt.annotation.Nullable;
18 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
19
20 import com.google.common.base.MoreObjects;
21 import com.google.common.collect.ImmutableList;
22
23 /**
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.
27 *
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
31 * in the timegraph.
32 *
33 * @author Alexandre Montplaisir
34 */
35 public class TimeGraphTreeElement {
36
37 /** Non-null reference to a dummy element */
38 public static final TimeGraphTreeElement DUMMY_ELEMENT = new TimeGraphTreeElement("Dummy", Collections.emptyList()); //$NON-NLS-1$
39
40 private final String fName;
41 private final List<TimeGraphTreeElement> fChildElements;
42
43 /**
44 * Constructor, build a tree element by specifying its name and children
45 * elements.
46 *
47 * @param name
48 * The name this tree element should have.
49 * @param children
50 * The children tree elements. You can pass an empty list for no
51 * children.
52 */
53 public TimeGraphTreeElement(String name, List<TimeGraphTreeElement> children) {
54 fName = name;
55 fChildElements = ImmutableList.copyOf(children);
56 }
57
58 /**
59 * Get the name of this tree element.
60 *
61 * @return The element's name
62 */
63 public String getName() {
64 return fName;
65 }
66
67 /**
68 * Get the child elements of this tree element.
69 *
70 * @return The child elements
71 */
72 public List<TimeGraphTreeElement> getChildElements() {
73 return fChildElements;
74 }
75
76 /**
77 * Determine if and how this tree element corresponds to a component of a
78 * trace event.
79 *
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.
82 *
83 * The method returns null if this tree element does not correspond to a
84 * particular aspect of trace events.
85 *
86 * @return The event matching predicate, if there is one
87 */
88 public @Nullable Predicate<ITmfEvent> getEventMatching() {
89 /* Sub-classes can override */
90 return null;
91 }
92
93 @Override
94 public int hashCode() {
95 return Objects.hash(fName, fChildElements);
96 }
97
98 @Override
99 public boolean equals(@Nullable Object obj) {
100 if (this == obj) {
101 return true;
102 }
103 if (obj == null) {
104 return false;
105 }
106 if (getClass() != obj.getClass()) {
107 return false;
108 }
109 TimeGraphTreeElement other = (TimeGraphTreeElement) obj;
110 return Objects.equals(fName, other.fName)
111 && Objects.equals(fChildElements, other.fChildElements);
112 }
113
114 @Override
115 public String toString() {
116 return MoreObjects.toStringHelper(this)
117 .add("fName", fName) //$NON-NLS-1$
118 .add("fChildElements", fChildElements.toString()) //$NON-NLS-1$
119 .toString();
120 }
121
122 }
This page took 0.033171 seconds and 5 git commands to generate.