analysis: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / 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 /**
17 * Generic TimeEvent implementation
18 *
19 * @version 1.0
20 * @author Patrick Tasse
21 */
22 public class TimeEvent implements ITimeEvent {
23
24 /** TimeGraphEntry matching this time event */
25 protected ITimeGraphEntry fEntry;
26
27 /** Beginning timestamp of this time event */
28 protected long fTime;
29
30 /** Duration of this time event */
31 protected long fDuration;
32
33 private final int fValue;
34
35 /**
36 * Default value when no other value present
37 */
38 private static final int NOVALUE = Integer.MIN_VALUE;
39
40 /**
41 * Standard constructor
42 *
43 * @param entry
44 * The entry matching this event
45 * @param time
46 * The timestamp of this event
47 * @param duration
48 * The duration of the event
49 */
50 public TimeEvent(ITimeGraphEntry entry, long time, long duration) {
51 this(entry, time, duration, NOVALUE);
52
53 }
54
55 /**
56 * Constructor
57 *
58 * @param entry
59 * The entry to which this time event is assigned
60 * @param time
61 * The timestamp of this event
62 * @param duration
63 * The duration of this event
64 * @param value
65 * The status assigned to the event
66 */
67 public TimeEvent(ITimeGraphEntry entry, long time, long duration,
68 int value) {
69 fEntry = entry;
70 fTime = time;
71 fDuration = duration;
72 fValue = value;
73 }
74
75 /**
76 * Get this event's status
77 *
78 * @return The integer matching this status
79 */
80 public int getValue() {
81 return fValue;
82 }
83
84 /**
85 * Return whether an event has a value
86 *
87 * @return true if the event has a value
88 */
89 public boolean hasValue() {
90 return (fValue != NOVALUE);
91 }
92
93 @Override
94 public ITimeGraphEntry getEntry() {
95 return fEntry;
96 }
97
98 @Override
99 public long getTime() {
100 return fTime;
101 }
102
103 @Override
104 public long getDuration() {
105 return fDuration;
106 }
107
108 @Override
109 public ITimeEvent splitBefore(long splitTime) {
110 return (splitTime > fTime ?
111 new TimeEvent(fEntry, fTime, Math.min(fDuration, splitTime - fTime), fValue) :
112 null);
113 }
114
115 @Override
116 public ITimeEvent splitAfter(long splitTime) {
117 return (splitTime < fTime + fDuration ?
118 new TimeEvent(fEntry, Math.max(fTime, splitTime), fDuration - Math.max(0, splitTime - fTime),
119 fValue) :
120 null);
121 }
122
123 @Override
124 public String toString() {
125 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$
126 }
127 }
This page took 0.034685 seconds and 5 git commands to generate.