tmf: Consolidate all enviornment-related methods in CtfTmfTrace
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 14 May 2013 18:55:07 +0000 (14:55 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Thu, 16 May 2013 19:37:37 +0000 (15:37 -0400)
Change-Id: I90d8fbdfb132533a26c8911982c6e77b505a6913
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/12788
Tested-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
IP-Clean: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfTraceTest.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/environment/TmfEnvironmentView.java

index 24572e2663afa8cf95cc263af81969af986b23ec..c64cc3f3ec788cea22563ebc697469052fb38c2a 100644 (file)
@@ -175,21 +175,12 @@ public class CtfTmfTraceTest {
     }
 
     /**
-     * Run the String[] getEnvNames() method test.
-     */
-    @Test
-    public void testGetEnvNames() {
-        String[] result = fixture.getEnvNames();
-        assertNotNull(result);
-    }
-
-    /**
-     * Run the String getEnvValue(String) method test.
+     * Run the String getEnvironment method test.
      */
     @Test
     public void testGetEnvValue() {
         String key = "tracer_name";
-        String result = fixture.getEnvValue(key);
+        String result = fixture.getEnvironment().get(key);
         assertEquals("\"lttng-modules\"",result);
     }
 
@@ -228,7 +219,7 @@ public class CtfTmfTraceTest {
      */
     @Test
     public void testGetNbEnvVars() {
-        int result = fixture.getNbEnvVars();
+        int result = fixture.getEnvironment().size();
         assertEquals(8, result);
     }
 
index 8375eaad91823b82245dcdf243a0b74ded389797..7e6a89923f8323551017cf4f5d0d8af3f3989bd5 100644 (file)
@@ -13,6 +13,9 @@
 
 package org.eclipse.linuxtools.tmf.core.ctfadaptor;
 
+import java.util.Collections;
+import java.util.Map;
+
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.IStatus;
@@ -277,34 +280,15 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParser {
     // -------------------------------------------
     // Environment Parameters
     // -------------------------------------------
-    /**
-     * Method getNbEnvVars.
-     *
-     * @return int
-     */
-    public int getNbEnvVars() {
-        return this.fTrace.getEnvironment().size();
-    }
-
-    /**
-     * Method getEnvNames.
-     *
-     * @return String[]
-     */
-    public String[] getEnvNames() {
-        final String[] s = new String[getNbEnvVars()];
-        return this.fTrace.getEnvironment().keySet().toArray(s);
-    }
 
     /**
-     * Method getEnvValue.
+     * Get the map of environment variables of this trace.
      *
-     * @param key
-     *            String
-     * @return String
+     * @return The map of env vars
+     * @since 2.0
      */
-    public String getEnvValue(final String key) {
-        return this.fTrace.getEnvironment().get(key);
+    public Map<String, String> getEnvironment() {
+        return Collections.unmodifiableMap(fTrace.getEnvironment());
     }
 
     // -------------------------------------------
index 5e7d0745eefd15db7f363a529aae5a7af78819a6..836a588c73cdcbde354be964e748cee1da7d5cc4 100644 (file)
@@ -12,6 +12,8 @@
  *******************************************************************************/
 package org.eclipse.linuxtools.tmf.ui.views.environment;
 
+import java.util.Map;
+
 import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace;
 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceClosedSignal;
@@ -78,14 +80,18 @@ public class TmfEnvironmentView extends TmfView {
         }
 
         for (ITmfTrace trace : TmfTraceManager.getTraceSet(fTrace)) {
+            // FIXME This should be replaced with a method in ITmfTrace maybe?
+            // Other trace types might want to supply environment variables.
             if (trace instanceof CtfTmfTrace) {
                 TreeItem item = new TreeItem(fTree, SWT.NONE);
                 item.setText(0, trace.getName());
+
                 CtfTmfTrace ctfTrace = (CtfTmfTrace) trace;
-                for (String varName : ctfTrace.getEnvNames()) {
+                Map <String, String> env = ctfTrace.getEnvironment();
+                for (Map.Entry<String, String> entry : env.entrySet()) {
                     TreeItem subItem = new TreeItem(item, SWT.NONE);
-                    subItem.setText(0, varName);
-                    subItem.setText(1, ctfTrace.getEnvValue(varName));
+                    subItem.setText(0, entry.getKey()); // Variable name
+                    subItem.setText(1, entry.getValue()); // Variable value
                 }
             }
         }
This page took 0.028909 seconds and 5 git commands to generate.