tmf: Drop generics from ITmfTrace and TmfExperiment
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / internal / tmf / core / request / TmfCoalescedEventRequest.java
index 1cb9c33fceb215d2825ab2515af9566be441afc4..7fb6cebd248abc2930381a1a1f4384a8abf0985e 100644 (file)
@@ -1,11 +1,11 @@
 /*******************************************************************************
  * Copyright (c) 2009, 2010 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:
  *   Francois Chouinard - Initial API and implementation
  *******************************************************************************/
@@ -19,15 +19,14 @@ import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
 import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
 import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
 import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
-import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
 
 /**
  * The TMF coalesced event request
- * 
+ *
  * @version 1.0
  * @author Francois Chouinard
  */
-public class TmfCoalescedEventRequest<T extends ITmfEvent> extends TmfCoalescedDataRequest<T> implements ITmfEventRequest<T> {
+public class TmfCoalescedEventRequest extends TmfCoalescedDataRequest implements ITmfEventRequest {
 
     // ------------------------------------------------------------------------
     // Attributes
@@ -42,103 +41,103 @@ public class TmfCoalescedEventRequest<T extends ITmfEvent> extends TmfCoalescedD
     /**
      * Request all the events of a given type (high priority)
      * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
-     * 
+     *
      * @param dataType the requested data type
      */
-    public TmfCoalescedEventRequest(Class<T> dataType) {
+    public TmfCoalescedEventRequest(Class<? extends ITmfEvent> dataType) {
         this(dataType, TmfTimeRange.ETERNITY, ALL_DATA, DEFAULT_BLOCK_SIZE, ExecutionType.FOREGROUND);
     }
 
     /**
      * Request all the events of a given type (given priority)
      * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
-     * 
+     *
      * @param dataType the requested data type
      * @param priority the requested execution priority
      */
-    public TmfCoalescedEventRequest(Class<T> dataType, ExecutionType priority) {
+    public TmfCoalescedEventRequest(Class<? extends ITmfEvent> dataType, ExecutionType priority) {
         this(dataType, TmfTimeRange.ETERNITY, ALL_DATA, DEFAULT_BLOCK_SIZE, priority);
     }
 
     /**
      * Request all the events of a given type for the given time range (high priority)
      * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
-     * 
+     *
      * @param dataType the requested data type
      * @param range the time range of the requested events
      */
-    public TmfCoalescedEventRequest(Class<T> dataType, TmfTimeRange range) {
+    public TmfCoalescedEventRequest(Class<? extends ITmfEvent> dataType, TmfTimeRange range) {
         this(dataType, range, ALL_DATA, DEFAULT_BLOCK_SIZE, ExecutionType.FOREGROUND);
     }
 
     /**
      * Request all the events of a given type for the given time range (given priority)
      * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
-     * 
+     *
      * @param dataType the requested data type
      * @param range the time range of the requested events
      * @param priority the requested execution priority
      */
-    public TmfCoalescedEventRequest(Class<T> dataType, TmfTimeRange range, ExecutionType priority) {
+    public TmfCoalescedEventRequest(Class<? extends ITmfEvent> dataType, TmfTimeRange range, ExecutionType priority) {
         this(dataType, range, ALL_DATA, DEFAULT_BLOCK_SIZE, priority);
     }
 
     /**
      * Request 'n' events of a given type from the given time range (high priority)
      * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
-     * 
+     *
      * @param dataType the requested data type
      * @param range the time range of the requested events
      * @param nbRequested the number of events requested
      */
-    public TmfCoalescedEventRequest(Class<T> dataType, TmfTimeRange range, int nbRequested) {
+    public TmfCoalescedEventRequest(Class<? extends ITmfEvent> dataType, TmfTimeRange range, int nbRequested) {
         this(dataType, range, nbRequested, DEFAULT_BLOCK_SIZE, ExecutionType.FOREGROUND);
     }
 
     /**
      * Request 'n' events of a given type for the given time range (given priority)
      * Events are returned in blocks of the default size (DEFAULT_BLOCK_SIZE).
-     * 
+     *
      * @param dataType the requested data type
      * @param range the time range of the requested events
      * @param nbRequested the number of events requested
      * @param priority the requested execution priority
      */
-    public TmfCoalescedEventRequest(Class<T> dataType, TmfTimeRange range, int nbRequested, ExecutionType priority) {
+    public TmfCoalescedEventRequest(Class<? extends ITmfEvent> dataType, TmfTimeRange range, int nbRequested, ExecutionType priority) {
         this(dataType, range, nbRequested, DEFAULT_BLOCK_SIZE, priority);
     }
 
     /**
      * Request 'n' events of a given type for the given time range (high priority).
      * Events are returned in blocks of the given size.
-     * 
+     *
      * @param dataType the requested data type
      * @param range the time range of the requested events
      * @param nbRequested the number of events requested
      * @param blockSize the number of events per block
      */
-    public TmfCoalescedEventRequest(Class<T> dataType, TmfTimeRange range, int nbRequested, int blockSize) {
+    public TmfCoalescedEventRequest(Class<? extends ITmfEvent> dataType, TmfTimeRange range, int nbRequested, int blockSize) {
         this(dataType, range, 0, nbRequested, blockSize, ExecutionType.FOREGROUND);
     }
 
     /**
      * Request 'n' events of a given type for the given time range (given priority).
      * Events are returned in blocks of the given size.
-     * 
+     *
      * @param dataType the requested data type
      * @param range the time range of the requested events
      * @param nbRequested the number of events requested
      * @param blockSize the number of events per block
      * @param priority the requested execution priority
      */
-    public TmfCoalescedEventRequest(Class<T> dataType, TmfTimeRange range, int nbRequested, int blockSize, ExecutionType priority) {
+    public TmfCoalescedEventRequest(Class<? extends ITmfEvent> dataType, TmfTimeRange range, int nbRequested, int blockSize, ExecutionType priority) {
         this(dataType, range, 0, nbRequested, blockSize, priority);
     }
 
     /**
      * Request 'n' events of a given type for the given time range (given priority).
      * Events are returned in blocks of the given size.
-     * 
+     *
      * @param dataType the requested data type
      * @param range the time range of the requested events
      * @param index the index of the first event to retrieve
@@ -146,7 +145,7 @@ public class TmfCoalescedEventRequest<T extends ITmfEvent> extends TmfCoalescedD
      * @param blockSize the number of events per block
      * @param priority the requested execution priority
      */
-    public TmfCoalescedEventRequest(Class<T> dataType, TmfTimeRange range, long index, int nbRequested, int blockSize, ExecutionType priority) {
+    public TmfCoalescedEventRequest(Class<? extends ITmfEvent> dataType, TmfTimeRange range, long index, int nbRequested, int blockSize, ExecutionType priority) {
         super(dataType, index, nbRequested, blockSize, priority);
         fRange = range;
 
@@ -154,9 +153,9 @@ public class TmfCoalescedEventRequest<T extends ITmfEvent> extends TmfCoalescedD
             String type = getClass().getName();
             type = type.substring(type.lastIndexOf('.') + 1);
             @SuppressWarnings("nls")
-            String message = "CREATED " 
-                    + (getExecType() == ITmfDataRequest.ExecutionType.BACKGROUND ? "(BG)" : "(FG)") 
-                    + " Type=" + type + " Index=" + getIndex() + " NbReq=" + getNbRequested() 
+            String message = "CREATED "
+                    + (getExecType() == ITmfDataRequest.ExecutionType.BACKGROUND ? "(BG)" : "(FG)")
+                    + " Type=" + type + " Index=" + getIndex() + " NbReq=" + getNbRequested()
                     + " Range=" + getRange()
                     + " DataType=" + getDataType().getSimpleName();
             Tracer.traceRequest(this, message);
@@ -168,32 +167,32 @@ public class TmfCoalescedEventRequest<T extends ITmfEvent> extends TmfCoalescedD
     // ------------------------------------------------------------------------
 
     @Override
-    public void addRequest(ITmfDataRequest<T> request) {
+    public void addRequest(ITmfDataRequest request) {
         super.addRequest(request);
-        if (request instanceof ITmfEventRequest<?>) {
-            merge((ITmfEventRequest<T>) request);
+        if (request instanceof ITmfEventRequest) {
+            merge((ITmfEventRequest) request);
         }
     }
 
        @Override
-       public boolean isCompatible(ITmfDataRequest<T> request) {
-           if (request instanceof ITmfEventRequest<?>) {
+       public boolean isCompatible(ITmfDataRequest request) {
+           if (request instanceof ITmfEventRequest) {
                if (super.isCompatible(request)) {
-                   return overlaps((ITmfEventRequest<T>) request);
+                   return overlaps((ITmfEventRequest) request);
                }
            }
            return false;
        }
 
-    private boolean overlaps(ITmfEventRequest<T> request) {
-        ITmfTimestamp startTime = ((ITmfEventRequest<T>) request).getRange().getStartTime();
-        ITmfTimestamp endTime   = ((ITmfEventRequest<T>) request).getRange().getEndTime();
+    private boolean overlaps(ITmfEventRequest request) {
+        ITmfTimestamp startTime = request.getRange().getStartTime();
+        ITmfTimestamp endTime   = request.getRange().getEndTime();
         return (startTime.compareTo(endTime) <= 0) && (fRange.getStartTime().compareTo(fRange.getEndTime()) <= 0);
     }
 
-    private void merge(ITmfEventRequest<T> request) {
-        ITmfTimestamp startTime = ((ITmfEventRequest<T>) request).getRange().getStartTime();
-        ITmfTimestamp endTime   = ((ITmfEventRequest<T>) request).getRange().getEndTime();
+    private void merge(ITmfEventRequest request) {
+        ITmfTimestamp startTime = request.getRange().getStartTime();
+        ITmfTimestamp endTime   = request.getRange().getEndTime();
         if (!fRange.contains(startTime) && fRange.getStartTime().compareTo(startTime) > 0) {
             fRange = new TmfTimeRange(startTime, fRange.getEndTime());
         }
@@ -207,15 +206,18 @@ public class TmfCoalescedEventRequest<T extends ITmfEvent> extends TmfCoalescedD
     // ------------------------------------------------------------------------
 
     @Override
-    public void handleData(T data) {
+    public void handleData(ITmfEvent data) {
         super.handleData(data);
-        for (ITmfDataRequest<T> request : fRequests) {
+        long index = getIndex() + getNbRead() - 1;
+        for (ITmfDataRequest request : fRequests) {
             if (data == null) {
                 request.handleData(null);
             } else {
-                if (request instanceof TmfEventRequest<?>) {
-                    TmfEventRequest<T> req = (TmfEventRequest<T>) request;
-                    if (!req.isCompleted() && (getNbRead() > request.getIndex())) {
+                long start = request.getIndex();
+                long end = start + request.getNbRequested();
+                if (request instanceof ITmfEventRequest) {
+                    ITmfEventRequest req = (ITmfEventRequest) request;
+                    if (!req.isCompleted() && index >= start && index < end) {
                         ITmfTimestamp ts = data.getTimestamp();
                         if (req.getRange().contains(ts)) {
                             if (req.getDataType().isInstance(data)) {
@@ -225,8 +227,8 @@ public class TmfCoalescedEventRequest<T extends ITmfEvent> extends TmfCoalescedD
                     }
                 }
                 else {
-                    TmfDataRequest<T> req = (TmfDataRequest<T>) request;
-                    if (!req.isCompleted()) {
+                    TmfDataRequest req = (TmfDataRequest) request;
+                    if (!req.isCompleted() && index >= start && index < end) {
                         if (req.getDataType().isInstance(data)) {
                             req.handleData(data);
                         }
@@ -244,12 +246,12 @@ public class TmfCoalescedEventRequest<T extends ITmfEvent> extends TmfCoalescedD
        public TmfTimeRange getRange() {
                return fRange;
        }
-       
+
        @Override
        public void setStartIndex(int index) {
                setIndex(index);
        }
-       
+
     // ------------------------------------------------------------------------
     // Object
     // ------------------------------------------------------------------------
@@ -262,14 +264,14 @@ public class TmfCoalescedEventRequest<T extends ITmfEvent> extends TmfCoalescedD
 
     @Override
     public boolean equals(Object other) {
-       if (other instanceof TmfCoalescedEventRequest<?>) {
-               TmfCoalescedEventRequest<?> request = (TmfCoalescedEventRequest<?>) other;
+       if (other instanceof TmfCoalescedEventRequest) {
+               TmfCoalescedEventRequest request = (TmfCoalescedEventRequest) other;
                        return  (request.getDataType()    == getDataType()) &&
                                        (request.getIndex()       == getIndex())    &&
                                        (request.getNbRequested() == getNbRequested()) &&
                                (request.getRange().equals(getRange()));
                }
-       if (other instanceof TmfCoalescedDataRequest<?>) {
+       if (other instanceof TmfCoalescedDataRequest) {
                        return super.equals(other);
        }
                return false;
@@ -278,7 +280,7 @@ public class TmfCoalescedEventRequest<T extends ITmfEvent> extends TmfCoalescedD
     @Override
     @SuppressWarnings("nls")
     public String toString() {
-               return "[TmfCoalescedEventRequest(" + getRequestId() + "," + getDataType().getSimpleName() 
+               return "[TmfCoalescedEventRequest(" + getRequestId() + "," + getDataType().getSimpleName()
                        + "," + getRange() + "," + getIndex() + "," + getNbRequested() + "," + getBlockSize() + ")]";
     }
 
This page took 0.028276 seconds and 5 git commands to generate.