ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / widgets / timegraph / model / TimeEvent.java
index 69d1dcd0b0cf59991bc6e1de96dd947bd26c3a40..7dc8ba571d774c4d0365d589e260d59bfc29b41e 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2012 Ericsson\r
- *\r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *   Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model;\r
-\r
-/**\r
- * Generic TimeEvent implementation\r
- *\r
- * @version 1.0\r
- * @author Patrick Tasse\r
- */\r
-public class TimeEvent implements ITimeEvent {\r
-    protected ITimeGraphEntry fEntry;\r
-    protected long fTime;\r
-    protected long fDuration;\r
-\r
-    public TimeEvent(ITimeGraphEntry entry, long time, long duration) {\r
-        fEntry = entry;\r
-        fTime = time;\r
-        fDuration = duration;\r
-    }\r
-\r
-    @Override\r
-    public ITimeGraphEntry getEntry() {\r
-        return fEntry;\r
-    }\r
-\r
-    @Override\r
-    public long getTime() {\r
-        return fTime;\r
-    }\r
-\r
-    @Override\r
-    public long getDuration() {\r
-        return fDuration;\r
-    }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Patrick Tasse - Initial API and implementation
+ *   Geneviève Bastien - Added the fValue parameter to avoid subclassing
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model;
+
+import org.eclipse.linuxtools.tmf.core.util.Pair;
+
+/**
+ * Generic TimeEvent implementation
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public class TimeEvent implements ITimeEvent2 {
+
+    /** TimeGraphEntry matching this time event */
+    protected ITimeGraphEntry fEntry;
+
+    /** Beginning timestamp of this time event */
+    protected long fTime;
+
+    /** Duration of this time event */
+    protected long fDuration;
+
+    private final int fValue;
+
+    /**
+     * Default value when no other value present
+     */
+    private static final int NOVALUE = Integer.MIN_VALUE;
+
+    /**
+     * Standard constructor
+     *
+     * @param entry
+     *            The entry matching this event
+     * @param time
+     *            The timestamp of this event
+     * @param duration
+     *            The duration of the event
+     */
+    public TimeEvent(ITimeGraphEntry entry, long time, long duration) {
+        this(entry, time, duration, NOVALUE);
+
+    }
+
+    /**
+     * Constructor
+     *
+     * @param entry
+     *            The entry to which this time event is assigned
+     * @param time
+     *            The timestamp of this event
+     * @param duration
+     *            The duration of this event
+     * @param value
+     *            The status assigned to the event
+     * @since 2.1
+     */
+    public TimeEvent(ITimeGraphEntry entry, long time, long duration,
+            int value) {
+        fEntry = entry;
+        fTime = time;
+        fDuration = duration;
+        fValue = value;
+    }
+
+    /**
+     * Get this event's status
+     *
+     * @return The integer matching this status
+     * @since 2.1
+     */
+    public int getValue() {
+        return fValue;
+    }
+
+    /**
+     * Return whether an event has a value
+     *
+     * @return true if the event has a value
+     * @since 2.1
+     */
+    public boolean hasValue() {
+        return (fValue != NOVALUE);
+    }
+
+    @Override
+    public ITimeGraphEntry getEntry() {
+        return fEntry;
+    }
+
+    @Override
+    public long getTime() {
+        return fTime;
+    }
+
+    @Override
+    public long getDuration() {
+        return fDuration;
+    }
+
+    /**
+     * Split an event in two at the specified time. If the time is smaller or
+     * equal to the event's start, the first split event is null. If the time is
+     * greater or equal to the event's end, the second split event is null.
+     * <p>
+     * Subclasses should re-implement this method
+     *
+     * @since 2.1
+     */
+    @Override
+    public Pair<ITimeEvent, ITimeEvent> split(long time) {
+        Pair<ITimeEvent, ITimeEvent> pair = new Pair<>();
+        if (time > fTime) {
+            pair.setFirst(new TimeEvent(fEntry, fTime, Math.min(fDuration, time - fTime), fValue));
+        }
+        if (time < fTime + fDuration) {
+            pair.setSecond(new TimeEvent(fEntry, Math.max(fTime, time), fDuration - Math.max(0, time - fTime), fValue));
+        }
+        return pair;
+    }
+
+    @Override
+    public String toString() {
+        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.026915 seconds and 5 git commands to generate.