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;
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 {
}
+ @Override
+ public int getLength() {
+ return fContent.length;
+ }
+
@Override
public synchronized List<Definition> getDefinitions() {
List<Definition> defs = fDefs;
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;
@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