tmf: keep event fields ordering as per ctf metadata
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / event / types / StructDefinition.java
index 41fcb66c8081910e8acd139538e26829dfea2a6a..b7603497b473c06ab4ee7b00a0b90cc3b61c3b7d 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
+ * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal and others
  *
  * All rights reserved. This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License v1.0 which
 
 package org.eclipse.linuxtools.ctf.core.event.types;
 
-import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.ListIterator;
+import java.util.Map;
 
-import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
 
 /**
  * A CTF structure definition (similar to a C structure).
- * 
+ *
  * A structure is similar to a C structure, it is a compound data type that
  * contains other datatypes in fields. they are stored in an hashmap and indexed
  * by names which are strings.
@@ -36,7 +37,7 @@ public class StructDefinition extends Definition implements IDefinitionScope {
     // ------------------------------------------------------------------------
 
     private final StructDeclaration declaration;
-    private final HashMap<String, Definition> definitions = new HashMap<String, Definition>();
+    private final Map<String, Definition> definitions = new LinkedHashMap<String, Definition>();
 
     // ------------------------------------------------------------------------
     // Constructors
@@ -78,8 +79,9 @@ public class StructDefinition extends Definition implements IDefinitionScope {
 
     /**
      * @return The definitions of all the fields
+     * @since 2.0
      */
-    public HashMap<String, Definition> getDefinitions() {
+    public Map<String, Definition> getDefinitions() {
         return definitions;
     }
 
@@ -220,28 +222,24 @@ public class StructDefinition extends Definition implements IDefinitionScope {
     public String toString() {
         StringBuilder builder = new StringBuilder();
 
-        int size = this.declaration.getFieldsList().size();
-        int n = 0;
-
-        if (size > 1) {
-            builder.append("{ "); //$NON-NLS-1$
-        }
+        builder.append("{ "); //$NON-NLS-1$
 
         ListIterator<String> listIterator = this.declaration.getFieldsList()
                 .listIterator();
 
         while (listIterator.hasNext()) {
             String field = listIterator.next();
+
+            builder.append(field);
+            builder.append(" = "); //$NON-NLS-1$
             builder.append(lookupDefinition(field).toString());
-            n++;
-            if (n != size) {
+
+            if (listIterator.hasNext()) {
                 builder.append(", "); //$NON-NLS-1$
             }
         }
 
-        if (size > 1) {
-            builder.append(" }"); //$NON-NLS-1$
-        }
+        builder.append(" }"); //$NON-NLS-1$
 
         return builder.toString();
     }
This page took 0.024968 seconds and 5 git commands to generate.