rcp: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.ctf.core / src / org / eclipse / tracecompass / internal / ctf / core / event / types / ByteArrayDefinition.java
index b6ac66eb144d32792e7f0d13a37009e7f569e63d..abc0f334df0e0f4dd9a0514a27c30de346d3ede4 100644 (file)
 
 package org.eclipse.tracecompass.internal.ctf.core.event.types;
 
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
 import java.util.Arrays;
 import java.util.List;
 
-import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.common.core.NonNullUtils;
 import org.eclipse.tracecompass.ctf.core.event.scope.IDefinitionScope;
 import org.eclipse.tracecompass.ctf.core.event.types.AbstractArrayDefinition;
 import org.eclipse.tracecompass.ctf.core.event.types.CompoundDeclaration;
@@ -25,13 +27,13 @@ import org.eclipse.tracecompass.ctf.core.event.types.Definition;
 import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration;
 import org.eclipse.tracecompass.ctf.core.event.types.IntegerDefinition;
 
+import com.google.common.base.Joiner;
 import com.google.common.collect.ImmutableList;
 
 /**
  * A fixed length string definition
  *
  * @author Matthew Khouzam
- * @since 3.1
  */
 @NonNullByDefault
 public final class ByteArrayDefinition extends AbstractArrayDefinition {
@@ -61,6 +63,11 @@ public final class ByteArrayDefinition extends AbstractArrayDefinition {
 
     }
 
+    @Override
+    public int getLength() {
+        return fContent.length;
+    }
+
     @Override
     public synchronized List<Definition> getDefinitions() {
         List<Definition> defs = fDefs;
@@ -72,10 +79,8 @@ public final class ByteArrayDefinition extends AbstractArrayDefinition {
                 byte fieldValue = fContent[i];
                 builder.add(new IntegerDefinition(charDecl, getDefinitionScope(), fieldName, fieldValue));
             }
-            @SuppressWarnings("null")
-            @NonNull List<Definition> ret = builder.build();
-            fDefs = ret;
-            return ret;
+            fDefs = NonNullUtils.checkNotNull(builder.build());
+            return fDefs;
         }
 
         return defs;
@@ -83,18 +88,25 @@ public final class ByteArrayDefinition extends AbstractArrayDefinition {
 
     @Override
     public String toString() {
-        /*
-         * the string is a byte array and may contain more than the string plus
-         * a null char, this will truncate it back to a null char
-         */
-        int pos = -1;
-        for (int i = 0; i < fContent.length; i++) {
-            if (fContent[i] == 0) {
-                pos = i;
-                break;
+        if (((CompoundDeclaration) getDeclaration()).isString()) {
+            /*
+             * the string is a byte array and may contain more than the string
+             * plus a null char, this will truncate it back to a null char
+             */
+            int pos = -1;
+            for (int i = 0; i < fContent.length; i++) {
+                if (fContent[i] == 0) {
+                    pos = i;
+                    break;
+                }
             }
+            byte[] bytes = (pos != -1) ? (Arrays.copyOf(fContent, pos)) : fContent;
+            return new String(bytes);
         }
-        byte[] bytes = (pos != -1) ? (Arrays.copyOf(fContent, pos)) : fContent;
-        return new String(bytes);
+        StringBuilder b = new StringBuilder();
+        b.append('[');
+        Joiner.on(", ").appendTo(b, Arrays.asList(fContent)); //$NON-NLS-1$
+        b.append(']');
+        return checkNotNull(b.toString());
     }
 }
\ No newline at end of file
This page took 0.027115 seconds and 5 git commands to generate.