tmf: Split "CTF adaptor" into separate plugins/feature
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / event / matching / TmfEventMatching.java
index fe694f628f0b7e074fdbbaaca1b8ab9fe1b279cb..fbe88a308a1a7423cf0115bd0c98c41cf3a34f66 100644 (file)
 package org.eclipse.linuxtools.tmf.core.event.matching;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import org.eclipse.linuxtools.internal.tmf.core.Activator;
-import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
-import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
+import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
 import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
@@ -50,16 +49,16 @@ public abstract class TmfEventMatching implements ITmfEventMatching {
     /**
      * The array of traces to match
      */
-    private final ITmfTrace[] fTraces;
+    private final Collection<ITmfTrace> fTraces;
 
     /**
      * The class to call once a match is found
      */
     private final IMatchProcessingUnit fMatches;
 
-    private static final Map<MatchingType, List<ITmfMatchEventDefinition>> fMatchDefinitions = new HashMap<MatchingType, List<ITmfMatchEventDefinition>>();
+    private static final Map<MatchingType, List<ITmfMatchEventDefinition>> fMatchDefinitions = new HashMap<>();
 
-    private final Map<ITmfTrace, ITmfMatchEventDefinition> fMatchMap = new HashMap<ITmfTrace, ITmfMatchEventDefinition>();
+    private final Map<ITmfTrace, ITmfMatchEventDefinition> fMatchMap = new HashMap<>();
 
     /**
      * Constructor with multiple traces and a match processing object
@@ -69,7 +68,7 @@ public abstract class TmfEventMatching implements ITmfEventMatching {
      * @param tmfEventMatches
      *            The match processing class
      */
-    public TmfEventMatching(ITmfTrace[] traces, IMatchProcessingUnit tmfEventMatches) {
+    public TmfEventMatching(Collection<ITmfTrace> traces, IMatchProcessingUnit tmfEventMatches) {
         if (tmfEventMatches == null) {
             throw new IllegalArgumentException();
         }
@@ -82,7 +81,7 @@ public abstract class TmfEventMatching implements ITmfEventMatching {
      *
      * @return The traces
      */
-    protected ITmfTrace[] getTraces() {
+    protected Collection<? extends ITmfTrace> getTraces() {
         return fTraces;
     }
 
@@ -150,10 +149,10 @@ public abstract class TmfEventMatching implements ITmfEventMatching {
      *
      * @param event
      *            The event to match
-     * @param traceno
-     *            The number of the trace this event belongs to
+     * @param trace
+     *            The trace to which this event belongs
      */
-    protected abstract void matchEvent(ITmfEvent event, int traceno);
+    protected abstract void matchEvent(ITmfEvent event, ITmfTrace trace);
 
     /**
      * Returns the matching type this class implements
@@ -171,7 +170,7 @@ public abstract class TmfEventMatching implements ITmfEventMatching {
     public boolean matchEvents() {
 
         /* Are there traces to match? If no, return false */
-        if (!(fTraces.length > 0)) {
+        if (!(fTraces.size() > 0)) {
             return false;
         }
 
@@ -197,15 +196,14 @@ public abstract class TmfEventMatching implements ITmfEventMatching {
          * would be preferable to have experiment
          * </pre>
          */
-        for (int i = 0; i < fTraces.length; i++) {
-
-            EventMatchingBuildRequest request = new EventMatchingBuildRequest(this, i);
+        for (ITmfTrace trace : fTraces) {
+            EventMatchingBuildRequest request = new EventMatchingBuildRequest(this, trace);
 
             /*
              * Send the request to the trace here, since there is probably no
              * experiment.
              */
-            fTraces[i].sendRequest(request);
+            trace.sendRequest(request);
             try {
                 request.waitForCompletion();
             } catch (InterruptedException e) {
@@ -238,23 +236,23 @@ public abstract class TmfEventMatching implements ITmfEventMatching {
 class EventMatchingBuildRequest extends TmfEventRequest {
 
     private final TmfEventMatching matching;
-    private final int traceno;
+    private final ITmfTrace trace;
 
-    EventMatchingBuildRequest(TmfEventMatching matching, int traceno) {
-        super(CtfTmfEvent.class,
+    EventMatchingBuildRequest(TmfEventMatching matching, ITmfTrace trace) {
+        super(ITmfEvent.class,
                 TmfTimeRange.ETERNITY,
                 0,
-                TmfDataRequest.ALL_DATA,
-                ITmfDataRequest.ExecutionType.FOREGROUND);
+                ITmfEventRequest.ALL_DATA,
+                ITmfEventRequest.ExecutionType.FOREGROUND);
         this.matching = matching;
-        this.traceno = traceno;
+        this.trace = trace;
     }
 
     @Override
     public void handleData(final ITmfEvent event) {
         super.handleData(event);
         if (event != null) {
-            matching.matchEvent(event, traceno);
+            matching.matchEvent(event, trace);
         }
     }
 
This page took 0.028047 seconds and 5 git commands to generate.