tmf: Fold ITimeEvent2 into ITimeEvent
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Thu, 11 Dec 2014 14:55:38 +0000 (09:55 -0500)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Thu, 11 Dec 2014 19:47:08 +0000 (14:47 -0500)
Also split the one method in ITimeEvent2 into two separate ones,
since the Pair object was never used, so we can return the two
separate values directly.

Change-Id: Ia711b9cacf803b3afab1982a831478aef0bc38e1
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/38039
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-by: Hudson CI
org.eclipse.tracecompass.tmf.ui.tests/widgetStubs/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/test/stub/model/EventImpl.java
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/timechart/TimeChartEvent.java
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/model/EventIterator.java
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/model/ITimeEvent.java
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/model/ITimeEvent2.java [deleted file]
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/model/TimeEvent.java

index ab0b945316a90d1a3c36e6ec09021ee1fcacb310..927d94568252cf59b3e38b2b4c75b566154e2432 100644 (file)
@@ -82,4 +82,14 @@ public class EventImpl implements ITimeEvent {
         return duration;
     }
 
+    @Override
+    public ITimeEvent splitBefore(long splitTime) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public ITimeEvent splitAfter(long splitTime) {
+        throw new UnsupportedOperationException();
+    }
+
 }
index 9a5850cebc54c63d68a130064380f8935a2ae750..a5442f5a1bbc2f075969914f957ae9a555818d46 100644 (file)
@@ -19,6 +19,7 @@ import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
 import org.eclipse.tracecompass.tmf.ui.views.colors.ColorSettingsManager;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
+import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeEvent;
 
 /**
  * Event in the time chart view
@@ -85,6 +86,20 @@ public class TimeChartEvent implements ITimeEvent {
         return fDuration;
     }
 
+    @Override
+    public ITimeEvent splitBefore(long splitTime) {
+        return (splitTime > fTime ?
+                new TimeEvent(getEntry(), fTime, Math.min(fDuration, splitTime - fTime)) :
+                null);
+    }
+
+    @Override
+    public ITimeEvent splitAfter(long splitTime) {
+        return (splitTime < fTime + fDuration ?
+                new TimeEvent(getEntry(), Math.max(fTime, splitTime), fDuration - Math.max(0, splitTime - fTime)) :
+                null);
+    }
+
     /**
      * Retrieve the rank of the trace event which started this time event.
      *
index 3873afadcfbf01afe678dc46b2ed6024bbeb0384..f4119b53fb8ee79c82f6959d23c5e9a6cfd38ea3 100644 (file)
@@ -91,20 +91,12 @@ public class EventIterator implements Iterator<ITimeEvent> {
                         fNext = null;
                         if (event.getTime() + event.getDuration() > fZoomedEndTime && fZoomedEndTime < fEndTime) {
                             // the end of the event is partially hidden by the zoomed events and is visible
-                            if (event instanceof ITimeEvent2) {
-                                fNext = ((ITimeEvent2) event).split(fZoomedEndTime).getSecond();
-                            } else {
-                                fNext = new TimeEvent(event.getEntry(), fZoomedEndTime, event.getTime() + event.getDuration() - fZoomedEndTime);
-                            }
+                            fNext = event.splitAfter(fZoomedEndTime);
                         }
                         if (event.getTime() < fZoomedStartTime && fZoomedStartTime > fStartTime) {
                             // the start of the event is partially hidden by the zoomed events and is visible
                             fSplitNext = fNext;
-                            if (event instanceof ITimeEvent2) {
-                                fNext = ((ITimeEvent2) event).split(fZoomedStartTime).getFirst();
-                            } else {
-                                fNext = new TimeEvent(event.getEntry(), event.getTime(), fZoomedStartTime - event.getTime());
-                            }
+                            fNext = event.splitBefore(fZoomedStartTime);
                         }
                     }
                     if (fNext != null) {
index 5bc19eb9e1431a5a5eede99aefecde14519a0582..5bd1843918fd19be8e98da43f573f234456ba372 100644 (file)
@@ -47,4 +47,25 @@ public interface ITimeEvent {
      */
     long getDuration();
 
+    /**
+     * Split an event in two at the specified time and keep the part before the
+     * split. If the time is smaller or equal to the event's start, the returned
+     * event is null.
+     *
+     * @param splitTime
+     *            the time at which the event is to be split
+     * @return The part before the split time
+     */
+    ITimeEvent splitBefore(long splitTime);
+
+    /**
+     * Split an event in two at the specified time and keep the part after the
+     * split. If the time is greater or equal to the event's end, the returned
+     * event is null.
+     *
+     * @param splitTime
+     *            the time at which the event is to be split
+     * @return The part after the split time
+     */
+    ITimeEvent splitAfter(long splitTime);
 }
\ No newline at end of file
diff --git a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/model/ITimeEvent2.java b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/model/ITimeEvent2.java
deleted file mode 100644 (file)
index b982e2f..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 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
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model;
-
-import org.eclipse.tracecompass.tmf.core.util.Pair;
-
-/**
- * Extend ITimeEvent interface
- *
- * @author Patrick Tasse
- * @since 2.1
- */
-public interface ITimeEvent2 extends ITimeEvent {
-
-    /**
-     * 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.
-     *
-     * @param time
-     *            the time at which the event is to be split
-     * @return a pair of time events
-     */
-    Pair<ITimeEvent, ITimeEvent> split(long time);
-}
index d8995272035ffed22a5045bcf6b5de000a381003..daee3cb49a565d4468964cce0ab055faf63dd887 100644 (file)
 
 package org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model;
 
-import org.eclipse.tracecompass.tmf.core.util.Pair;
-
 /**
  * Generic TimeEvent implementation
  *
  * @version 1.0
  * @author Patrick Tasse
  */
-public class TimeEvent implements ITimeEvent2 {
+public class TimeEvent implements ITimeEvent {
 
     /** TimeGraphEntry matching this time event */
     protected ITimeGraphEntry fEntry;
@@ -110,25 +108,19 @@ public class TimeEvent implements ITimeEvent2 {
         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;
+    public ITimeEvent splitBefore(long splitTime) {
+        return (splitTime > fTime ?
+                new TimeEvent(fEntry, fTime, Math.min(fDuration, splitTime - fTime), fValue) :
+                null);
+    }
+
+    @Override
+    public ITimeEvent splitAfter(long splitTime) {
+        return (splitTime < fTime + fDuration ?
+                new TimeEvent(fEntry, Math.max(fTime, splitTime), fDuration - Math.max(0, splitTime - fTime),
+                        fValue) :
+                null);
     }
 
     @Override
This page took 0.029208 seconds and 5 git commands to generate.