Import views plugins
[deliverable/tracecompass.git] / tmf / org.lttng.scope.tmf2.views.core / src / org / lttng / scope / tmf2 / views / core / timegraph / model / render / states / BasicTimeGraphStateInterval.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.states;
11
12 import java.util.Map;
13 import java.util.Objects;
14
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.lttng.scope.tmf2.views.core.config.ConfigOption;
17 import org.lttng.scope.tmf2.views.core.timegraph.model.render.ColorDefinition;
18 import org.lttng.scope.tmf2.views.core.timegraph.model.render.LineThickness;
19 import org.lttng.scope.tmf2.views.core.timegraph.model.render.TimeGraphEvent;
20 import org.lttng.scope.tmf2.views.core.timegraph.model.render.tree.TimeGraphTreeElement;
21
22 import com.google.common.base.MoreObjects;
23
24 /**
25 * Basic implementation of {@link TimeGraphStateInterval}.
26 *
27 * @author Alexandre Montplaisir
28 */
29 public class BasicTimeGraphStateInterval implements TimeGraphStateInterval {
30
31 private final TimeGraphEvent fStartEvent;
32 private final TimeGraphEvent fEndEvent;
33
34 private final String fStateName;
35 private final @Nullable String fLabel;
36 private final ConfigOption<ColorDefinition> fColor;
37 private final ConfigOption<LineThickness> fLineThickness;
38
39 private final Map<String, String> fProperties;
40
41 /**
42 * Constructor.
43 *
44 * It requires supplying the start time, end time, and tree element. The
45 * corresponding {@link TimeGraphEvent} will be created from those.
46 *
47 * @param start
48 * Start time
49 * @param end
50 * End time
51 * @param treeElement
52 * Tree element of this interval
53 * @param stateName
54 * State name
55 * @param label
56 * Label, see {@link #getLabel()}
57 * @param color
58 * Color
59 * @param lineThickness
60 * Line thickness
61 * @param properties
62 * Properties
63 */
64 public BasicTimeGraphStateInterval(long start,
65 long end,
66 TimeGraphTreeElement treeElement,
67 String stateName,
68 @Nullable String label,
69 ConfigOption<ColorDefinition> color,
70 ConfigOption<LineThickness> lineThickness,
71 Map<String, String> properties) {
72
73 if (start > end || start < 0 || end < 0) {
74 throw new IllegalArgumentException();
75 }
76
77 fStartEvent = new TimeGraphEvent(start, treeElement);
78 fEndEvent = new TimeGraphEvent(end, treeElement);
79
80 fStateName = stateName;
81 fLabel = label;
82 fColor = color;
83 fLineThickness = lineThickness;
84 fProperties = properties;
85 }
86
87 @Override
88 public TimeGraphEvent getStartEvent() {
89 return fStartEvent;
90 }
91
92 @Override
93 public TimeGraphEvent getEndEvent() {
94 return fEndEvent;
95 }
96
97 @Override
98 public String getStateName() {
99 return fStateName;
100 }
101
102 @Override
103 public @Nullable String getLabel() {
104 return fLabel;
105 }
106
107 @Override
108 public ConfigOption<ColorDefinition> getColorDefinition() {
109 return fColor;
110 }
111
112 @Override
113 public ConfigOption<LineThickness> getLineThickness() {
114 return fLineThickness;
115 }
116
117 @Override
118 public boolean isMultiState() {
119 return false;
120 }
121
122 @Override
123 public Map<String, String> getProperties() {
124 return fProperties;
125 }
126
127 @Override
128 public int hashCode() {
129 return Objects.hash(fStartEvent, fEndEvent, fStateName, fLabel, fColor, fLineThickness);
130 }
131
132 @Override
133 public boolean equals(@Nullable Object obj) {
134 if (this == obj) {
135 return true;
136 }
137 if (obj == null) {
138 return false;
139 }
140 if (getClass() != obj.getClass()) {
141 return false;
142 }
143 BasicTimeGraphStateInterval other = (BasicTimeGraphStateInterval) obj;
144 return (Objects.equals(fStartEvent, other.fStartEvent)
145 && Objects.equals(fEndEvent, other.fEndEvent)
146 && Objects.equals(fStateName, other.fStateName)
147 && Objects.equals(fLabel, other.fLabel)
148 && Objects.equals(fColor, other.fColor)
149 && fLineThickness == other.fLineThickness);
150 }
151
152 @Override
153 public String toString() {
154 return MoreObjects.toStringHelper(this)
155 .add("start", fStartEvent.getTimestamp()) //$NON-NLS-1$
156 .add("end", fEndEvent.getTimestamp()) //$NON-NLS-1$
157 .add("name", fStateName) //$NON-NLS-1$
158 .toString();
159 }
160
161 }
This page took 0.034164 seconds and 5 git commands to generate.