}
- private static class TestEventAspect implements ITmfEventAspect<Integer> {
+ private static class TestEventAspect implements ITmfEventAspect<@NonNull Integer> {
public static final Integer RESOLVED_VALUE = 2;
public static final @NonNull String ASPECT_NAME = "test";
obj = TmfTraceUtils.resolveAspectOfNameForEvent(trace, TestEventAspect.ASPECT_NAME, event);
assertNull(obj);
+ Integer val = TmfTraceUtils.resolveIntEventAspectOfClassForEvent(trace, TestEventAspect.class, event);
+ assertNull(val);
+
// Register the aspect
TmfTraceUtils.registerEventAspect(new TestEventAspect());
// See that the aspect is resolved now
obj = TmfTraceUtils.resolveAspectOfNameForEvent(trace, TestEventAspect.ASPECT_NAME, event);
assertNotNull(obj);
assertEquals(TestEventAspect.RESOLVED_VALUE, obj);
+
+ // See if it is resolved by Integer type as well
+ val = TmfTraceUtils.resolveIntEventAspectOfClassForEvent(trace, TestEventAspect.class, event);
+ assertNotNull(val);
+ assertEquals(TestEventAspect.RESOLVED_VALUE, val);
}
}
*/
public static <T extends ITmfEventAspect<Integer>> @Nullable Integer resolveIntEventAspectOfClassForEvent(
ITmfTrace trace, Class<T> aspectClass, ITmfEvent event) {
- return StreamUtils.getStream(trace.getEventAspects())
+ Integer value = StreamUtils.getStream(trace.getEventAspects())
.filter(aspect -> aspectClass.isAssignableFrom(aspect.getClass()))
/* Enforced by the T parameter bounding */
.map(aspect -> (Integer) aspect.resolve(event))
.filter(obj -> obj != null)
.findFirst().orElse(null);
+ if (value != null) {
+ return value;
+ }
+ // If the value is not found, look at the global aspects
+ return EXTRA_ASPECTS.stream()
+ .filter(aspect -> aspectClass.isAssignableFrom(aspect.getClass()))
+ .map(aspect -> (Integer) aspect.resolve(event))
+ .filter(obj -> obj != null)
+ .findFirst().orElse(null);
}
/**