cf47461162f1e082276970fa01302ae8e09d7cf4
1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 Ericsson
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
10 * Patrick Tasse - Initial API and implementation
11 * Geneviève Bastien - Added the fValue parameter to avoid subclassing
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.ui
.widgets
.timegraph
.model
;
16 import org
.eclipse
.linuxtools
.tmf
.core
.util
.Pair
;
19 * Generic TimeEvent implementation
22 * @author Patrick Tasse
24 public class TimeEvent
implements ITimeEvent2
{
26 /** TimeGraphEntry matching this time event */
27 protected ITimeGraphEntry fEntry
;
29 /** Beginning timestamp of this time event */
32 /** Duration of this time event */
33 protected long fDuration
;
35 private final int fValue
;
38 * Default value when no other value present
40 private static final int NOVALUE
= Integer
.MIN_VALUE
;
43 * Standard constructor
46 * The entry matching this event
48 * The timestamp of this event
50 * The duration of the event
52 public TimeEvent(ITimeGraphEntry entry
, long time
, long duration
) {
53 this(entry
, time
, duration
, NOVALUE
);
61 * The entry to which this time event is assigned
63 * The timestamp of this event
65 * The duration of this event
67 * The status assigned to the event
70 public TimeEvent(ITimeGraphEntry entry
, long time
, long duration
,
79 * Get this event's status
81 * @return The integer matching this status
84 public int getValue() {
89 * Return whether an event has a value
91 * @return true if the event has a value
94 public boolean hasValue() {
95 return (fValue
!= NOVALUE
);
99 public ITimeGraphEntry
getEntry() {
104 public long getTime() {
109 public long getDuration() {
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.
118 * Subclasses should re-implement this method
123 public Pair
<ITimeEvent
, ITimeEvent
> split(long time
) {
124 Pair
<ITimeEvent
, ITimeEvent
> pair
= new Pair
<ITimeEvent
, ITimeEvent
>();
126 pair
.setFirst(new TimeEvent(fEntry
, fTime
, Math
.min(fDuration
, time
- fTime
), fValue
));
128 if (time
< fTime
+ fDuration
) {
129 pair
.setSecond(new TimeEvent(fEntry
, Math
.max(fTime
, time
), fDuration
- Math
.max(0, time
- fTime
), fValue
));
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$
This page took 0.063326 seconds and 4 git commands to generate.