tmf: Cache CallStackEvent names
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / widgets / timegraph / model / TimeEvent.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 2014 Ericsson
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 * Contributors:
10 * Patrick Tasse - Initial API and implementation
11 * Geneviève Bastien - Added the fValue parameter to avoid subclassing
12 *******************************************************************************/
13
14 package org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model;
15
16 import java.util.Objects;
17
18 /**
19 * Generic TimeEvent implementation
20 *
21 * @version 1.0
22 * @author Patrick Tasse
23 */
24 public class TimeEvent implements ITimeEvent {
25
26 /** TimeGraphEntry matching this time event */
27 protected ITimeGraphEntry fEntry;
28
29 /** Beginning timestamp of this time event */
30 protected long fTime;
31
32 /** Duration of this time event */
33 protected long fDuration;
34
35 private final int fValue;
36
37 /**
38 * Default value when no other value present
39 */
40 private static final int NOVALUE = Integer.MIN_VALUE;
41
42 /**
43 * Standard constructor
44 *
45 * @param entry
46 * The entry matching this event
47 * @param time
48 * The timestamp of this event
49 * @param duration
50 * The duration of the event
51 */
52 public TimeEvent(ITimeGraphEntry entry, long time, long duration) {
53 this(entry, time, duration, NOVALUE);
54
55 }
56
57 /**
58 * Constructor
59 *
60 * @param entry
61 * The entry to which this time event is assigned
62 * @param time
63 * The timestamp of this event
64 * @param duration
65 * The duration of this event
66 * @param value
67 * The status assigned to the event
68 */
69 public TimeEvent(ITimeGraphEntry entry, long time, long duration,
70 int value) {
71 fEntry = entry;
72 fTime = time;
73 fDuration = duration;
74 fValue = value;
75 }
76
77 /**
78 * Get this event's status
79 *
80 * @return The integer matching this status
81 */
82 public int getValue() {
83 return fValue;
84 }
85
86 /**
87 * Return whether an event has a value
88 *
89 * @return true if the event has a value
90 */
91 public boolean hasValue() {
92 return (fValue != NOVALUE);
93 }
94
95 @Override
96 public ITimeGraphEntry getEntry() {
97 return fEntry;
98 }
99
100 @Override
101 public long getTime() {
102 return fTime;
103 }
104
105 @Override
106 public long getDuration() {
107 return fDuration;
108 }
109
110 @Override
111 public ITimeEvent splitBefore(long splitTime) {
112 return (splitTime > fTime ?
113 new TimeEvent(fEntry, fTime, Math.min(fDuration, splitTime - fTime), fValue) :
114 null);
115 }
116
117 @Override
118 public ITimeEvent splitAfter(long splitTime) {
119 return (splitTime < fTime + fDuration ?
120 new TimeEvent(fEntry, Math.max(fTime, splitTime), fDuration - Math.max(0, splitTime - fTime),
121 fValue) :
122 null);
123 }
124
125 @Override
126 public int hashCode() {
127 return Objects.hash(fEntry, fTime, fDuration, fValue);
128 }
129
130 @Override
131 public boolean equals(Object obj) {
132 if (this == obj) {
133 return true;
134 }
135 if (obj == null) {
136 return false;
137 }
138 if (getClass() != obj.getClass()) {
139 return false;
140 }
141 TimeEvent other = (TimeEvent) obj;
142 return Objects.equals(fEntry, other.fEntry) &&
143 Objects.equals(fTime, other.fTime) &&
144 Objects.equals(fDuration, other.fDuration) &&
145 Objects.equals(fValue, other.fValue);
146 }
147
148 @Override
149 public String toString() {
150 return getClass().getSimpleName() + " start=" + fTime + " end=" + (fTime + fDuration) + " duration=" + fDuration + (hasValue() ? (" value=" + fValue) : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
151 }
152 }
This page took 0.042601 seconds and 5 git commands to generate.