use of org.eclipse.tracecompass.tmf.core.event.TmfEventType in project tracecompass by tracecompass.
the class TmfEventTypeTest method testDefaultConstructor.
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
@Test
public void testDefaultConstructor() {
final ITmfEventType type = new TmfEventType();
assertEquals("getName", ITmfEventType.DEFAULT_TYPE_ID, type.getName());
assertNull("getRootField", type.getRootField());
assertEquals("getFieldNames", 0, type.getFieldNames().size());
}
use of org.eclipse.tracecompass.tmf.core.event.TmfEventType in project tracecompass by tracecompass.
the class TmfEventTypeTest method testFullConstructor.
@Test
public void testFullConstructor() {
final ITmfEventType type0 = new TmfEventType(fTypeId1, TmfEventField.makeRoot(fLabels0));
assertEquals("getName", fTypeId1, type0.getName());
assertEquals("getRootField", TmfEventField.makeRoot(fLabels0), type0.getRootField());
final Collection<String> labels0 = type0.getFieldNames();
assertEquals("getFieldNames length", fLabels0.length, labels0.size());
assertArrayEquals(fLabels0, labels0.toArray(new String[labels0.size()]));
final ITmfEventType type1 = new TmfEventType(fTypeId1, TmfEventField.makeRoot(fLabels1));
assertEquals("getName", fTypeId1, type1.getName());
assertEquals("getRootField", TmfEventField.makeRoot(fLabels1), type1.getRootField());
final Collection<String> labels1 = type1.getFieldNames();
assertEquals("getFieldNames length", fLabels1.length, labels1.size());
assertArrayEquals(fLabels1, labels1.toArray(new String[labels1.size()]));
final ITmfEventType type2 = new TmfEventType(fTypeId2, TmfEventField.makeRoot(fLabels2));
assertEquals("getName", fTypeId2, type2.getName());
assertEquals("getRootField", TmfEventField.makeRoot(fLabels2), type2.getRootField());
final Collection<String> labels2 = type2.getFieldNames();
assertEquals("getFieldNames length", fLabels2.length, labels2.size());
assertArrayEquals(fLabels2, labels2.toArray(new String[labels2.size()]));
}
use of org.eclipse.tracecompass.tmf.core.event.TmfEventType in project tracecompass by tracecompass.
the class TmfEventTypeTest method testHashCode.
// ------------------------------------------------------------------------
// hashCode
// ------------------------------------------------------------------------
@Test
public void testHashCode() {
final TmfEventType copy1 = new TmfEventType(fType0);
assertTrue("hashCode", fType0.hashCode() == copy1.hashCode());
assertTrue("hashCode", fType0.hashCode() != fType3.hashCode());
}
use of org.eclipse.tracecompass.tmf.core.event.TmfEventType in project tracecompass by tracecompass.
the class TmfEventTypeTest method testToString.
// ------------------------------------------------------------------------
// toString
// ------------------------------------------------------------------------
@Test
public void testToString() {
final String expected1 = "TmfEventType [fTypeId=" + ITmfEventType.DEFAULT_TYPE_ID + "]";
final TmfEventType type1 = new TmfEventType();
assertEquals("toString", expected1, type1.toString());
final String expected2 = "TmfEventType [fTypeId=" + fTypeId1 + "]";
final TmfEventType type2 = new TmfEventType(fTypeId1, TmfEventField.makeRoot(fLabels1));
assertEquals("toString", expected2, type2.toString());
}
use of org.eclipse.tracecompass.tmf.core.event.TmfEventType in project tracecompass by tracecompass.
the class TmfXmlTraceStub method getNext.
@Override
@Nullable
public synchronized ITmfEvent getNext(@Nullable ITmfContext context) {
if (context == null) {
return null;
}
final ITmfContext savedContext = new TmfContext(context.getLocation(), context.getRank());
CustomXmlEvent event = fTrace.getNext(context);
if (event == null) {
return null;
}
/* Translate the content of the event */
/* The "fields" field contains a | separated list of field names */
/* The "values" field contains a | separated list of field values */
/* the "type" field contains a | separated list of field types */
ITmfEventField content = event.getContent();
if (content == null) {
return null;
}
String fieldString = getStringValue(content, FIELD_NAMES_FIELD);
String valueString = getStringValue(content, VALUES_FIELD);
String typeString = getStringValue(content, TYPES_FIELD);
String[] fields = fieldString.split(VALUES_SEPARATOR);
String[] values = valueString.split(VALUES_SEPARATOR);
String[] types = typeString.split(VALUES_SEPARATOR);
ITmfEventField[] fieldsArray = new TmfEventField[fields.length];
for (int i = 0; i < fields.length; i++) {
String value = EMPTY;
if (values.length > i) {
value = values[i];
}
String type = null;
if (types.length > i) {
type = types[i];
}
Object val = value;
if (type != null) {
switch(type) {
case TYPE_INTEGER:
{
try {
val = Integer.valueOf(value);
} catch (NumberFormatException e) {
// $NON-NLS-1$
Activator.logError(String.format("Get next XML event: cannot cast value %s to integer", value), e);
val = 0;
}
break;
}
case TYPE_LONG:
{
try {
val = Long.valueOf(value);
} catch (NumberFormatException e) {
// $NON-NLS-1$
Activator.logError(String.format("Get next XML event: cannot cast value %s to long", value), e);
val = 0L;
}
break;
}
case TYPE_LONG_ARRAY:
{
try {
String[] split = value.split(",");
long[] arr = new long[split.length];
for (int j = 0; j < split.length; j++) {
arr[j] = Long.valueOf(split[j]);
}
val = arr;
} catch (NumberFormatException e) {
// $NON-NLS-1$
Activator.logError(String.format("Get next XML event: cannot cast one of the comma-separated values of %s to long", value), e);
val = new long[0];
}
break;
}
case TYPE_INT_ARRAY:
{
try {
String[] split = value.split(",");
int[] arr = new int[split.length];
for (int j = 0; j < split.length; j++) {
arr[j] = Integer.valueOf(split[j]);
}
val = arr;
} catch (NumberFormatException e) {
// $NON-NLS-1$
Activator.logError(String.format("Get next XML event: cannot cast one of the comma-separated values of %s to int", value), e);
val = new int[0];
}
break;
}
default:
break;
}
}
fieldsArray[i] = new TmfEventField(checkNotNull(fields[i]), val, null);
}
/*
* Generate the aspects for this trace if it is the 'set_aspects'
* definition
*/
if (fTrace.getDefinition() != fDefinition) {
generateAspects(fieldsArray);
return null;
}
/* Create a new event with new fields and name */
ITmfEventType customEventType = event.getType();
String eventName = getStringValue(content, EVENT_NAME_FIELD);
TmfEventType eventType = new TmfEventType(eventName, customEventType.getRootField());
ITmfEventField eventFields = new CustomEventContent(content.getName(), content.getValue(), fieldsArray);
/*
* TODO: Timestamps for these traces are in nanos, but since the
* CustomXmlTrace does not support this format, the timestamp of the
* original is in second and we need to convert it. We should do that at
* the source when it is supported
*/
TmfEvent newEvent = new TmfEvent(this, ITmfContext.UNKNOWN_RANK, event.getTimestamp(), eventType, eventFields);
updateAttributes(savedContext, event);
return newEvent;
}
Aggregations