Commit | Line | Data |
---|---|---|
be222f56 | 1 | /******************************************************************************* |
ad128fd8 | 2 | * Copyright (c) 2012, 2013 Ericsson |
be222f56 PT |
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 | |
4999a196 | 11 | * Geneviève Bastien - Added the fValue parameter to avoid subclassing |
be222f56 PT |
12 | *******************************************************************************/ |
13 | ||
14 | package org.eclipse.linuxtools.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 { | |
a0a88f65 AM |
23 | |
24 | /** TimeGraphEntry matching this time event */ | |
be222f56 | 25 | protected ITimeGraphEntry fEntry; |
a0a88f65 AM |
26 | |
27 | /** Beginning timestamp of this time event */ | |
be222f56 | 28 | protected long fTime; |
a0a88f65 AM |
29 | |
30 | /** Duration of this time event */ | |
be222f56 PT |
31 | protected long fDuration; |
32 | ||
4999a196 GB |
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 | ||
be222f56 PT |
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) { | |
4999a196 GB |
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 | * @since 2.1 | |
67 | */ | |
68 | public TimeEvent(ITimeGraphEntry entry, long time, long duration, | |
69 | int value) { | |
be222f56 PT |
70 | fEntry = entry; |
71 | fTime = time; | |
72 | fDuration = duration; | |
4999a196 GB |
73 | fValue = value; |
74 | } | |
75 | ||
76 | /** | |
77 | * Get this event's status | |
78 | * | |
79 | * @return The integer matching this status | |
80 | * @since 2.1 | |
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 | * @since 2.1 | |
91 | */ | |
92 | public boolean hasValue() { | |
93 | return (fValue != NOVALUE); | |
be222f56 PT |
94 | } |
95 | ||
96 | @Override | |
97 | public ITimeGraphEntry getEntry() { | |
98 | return fEntry; | |
99 | } | |
100 | ||
101 | @Override | |
102 | public long getTime() { | |
103 | return fTime; | |
104 | } | |
105 | ||
106 | @Override | |
107 | public long getDuration() { | |
108 | return fDuration; | |
109 | } | |
ad128fd8 PT |
110 | |
111 | @Override | |
112 | public String toString() { | |
4999a196 | 113 | return "TimeEvent start=" + fTime + " end=" + (fTime + fDuration) + " duration=" + fDuration + " value=" + (hasValue() ? fValue : "N/A"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ |
ad128fd8 | 114 | } |
be222f56 | 115 | } |