tmf: Switch tmf.ui to Java 7 + fix warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / widgets / timegraph / model / TimeEvent.java
1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 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.linuxtools.tmf.ui.widgets.timegraph.model;
15
16 import org.eclipse.linuxtools.tmf.core.util.Pair;
17
18 /**
19 * Generic TimeEvent implementation
20 *
21 * @version 1.0
22 * @author Patrick Tasse
23 */
24 public class TimeEvent implements ITimeEvent2 {
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 * @since 2.1
69 */
70 public TimeEvent(ITimeGraphEntry entry, long time, long duration,
71 int value) {
72 fEntry = entry;
73 fTime = time;
74 fDuration = duration;
75 fValue = value;
76 }
77
78 /**
79 * Get this event's status
80 *
81 * @return The integer matching this status
82 * @since 2.1
83 */
84 public int getValue() {
85 return fValue;
86 }
87
88 /**
89 * Return whether an event has a value
90 *
91 * @return true if the event has a value
92 * @since 2.1
93 */
94 public boolean hasValue() {
95 return (fValue != NOVALUE);
96 }
97
98 @Override
99 public ITimeGraphEntry getEntry() {
100 return fEntry;
101 }
102
103 @Override
104 public long getTime() {
105 return fTime;
106 }
107
108 @Override
109 public long getDuration() {
110 return fDuration;
111 }
112
113 /**
114 * Split an event in two at the specified time. If the time is smaller or
115 * equal to the event's start, the first split event is null. If the time is
116 * greater or equal to the event's end, the second split event is null.
117 * <p>
118 * Subclasses should re-implement this method
119 *
120 * @since 2.1
121 */
122 @Override
123 public Pair<ITimeEvent, ITimeEvent> split(long time) {
124 Pair<ITimeEvent, ITimeEvent> pair = new Pair<>();
125 if (time > fTime) {
126 pair.setFirst(new TimeEvent(fEntry, fTime, Math.min(fDuration, time - fTime), fValue));
127 }
128 if (time < fTime + fDuration) {
129 pair.setSecond(new TimeEvent(fEntry, Math.max(fTime, time), fDuration - Math.max(0, time - fTime), fValue));
130 }
131 return pair;
132 }
133
134 @Override
135 public String toString() {
136 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$
137 }
138 }
This page took 0.035133 seconds and 5 git commands to generate.