return duration;
}
+ @Override
+ public ITimeEvent splitBefore(long splitTime) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ITimeEvent splitAfter(long splitTime) {
+ throw new UnsupportedOperationException();
+ }
+
}
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
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.
*
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) {
*/
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
+++ /dev/null
-/*******************************************************************************
- * 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);
-}
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;
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