| 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 | /** |
| 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 | * @since 2.1 |
| 67 | */ |
| 68 | public TimeEvent(ITimeGraphEntry entry, long time, long duration, |
| 69 | int value) { |
| 70 | fEntry = entry; |
| 71 | fTime = time; |
| 72 | fDuration = duration; |
| 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); |
| 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 | } |
| 110 | |
| 111 | @Override |
| 112 | public String toString() { |
| 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$ |
| 114 | } |
| 115 | } |