analysis: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / event / aspect / ITmfEventAspect.java
index 0a0c2d71625757ccda9019ab214aaa9c15506728..3a4da293905e7ba3b70950e148da7d8c38ef5c2e 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014 Ericsson
+ * Copyright (c) 2014, 2015 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are made
  * available under the terms of the Eclipse Public License v1.0 which
@@ -8,12 +8,22 @@
  *
  * Contributors:
  *   Alexandre Montplaisir - Initial API and implementation
+ *   Patrick Tasse - Added base aspect list
  *******************************************************************************/
 
 package org.eclipse.tracecompass.tmf.core.event.aspect;
 
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
+import java.util.List;
+
+import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEventType;
+import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
+
+import com.google.common.collect.ImmutableList;
 
 /**
  * An aspect is a piece of information that can be extracted, directly or
@@ -34,6 +44,16 @@ public interface ITmfEventAspect {
      */
     String EMPTY_STRING = ""; //$NON-NLS-1$
 
+    /**
+     * List of all common base aspects
+     */
+    public static final List<ITmfEventAspect> BASE_ASPECTS =
+            checkNotNull(ImmutableList.of(
+                    BaseAspects.TIMESTAMP,
+                    BaseAspects.EVENT_TYPE,
+                    BaseAspects.CONTENTS,
+                    BaseAspects.TRACE_NAME
+                    ));
     /**
      * Some basic aspects that all trace types should be able to use, using
      * methods found in {@link ITmfEvent}.
@@ -55,9 +75,8 @@ public interface ITmfEventAspect {
             }
 
             @Override
-            public String resolve(ITmfEvent event) {
-                String ret = event.getTimestamp().toString();
-                return (ret == null ? EMPTY_STRING : ret);
+            public @Nullable ITmfTimestamp resolve(ITmfEvent event) {
+                return event.getTimestamp();
             }
         };
 
@@ -76,35 +95,29 @@ public interface ITmfEventAspect {
             }
 
             @Override
-            public String resolve(ITmfEvent event) {
+            public @Nullable String resolve(ITmfEvent event) {
                 ITmfEventType type = event.getType();
                 if (type == null) {
-                    return EMPTY_STRING;
+                    return null;
                 }
-                String typeName = type.getName();
-                return (typeName == null ? EMPTY_STRING : typeName);
+                return type.getName();
             }
         };
 
         /**
          * Aspect for the aggregated event contents (fields)
          */
-        ITmfEventAspect CONTENTS = new ITmfEventAspect() {
+        TmfEventFieldAspect CONTENTS = new TmfEventFieldAspect(Messages.getMessage(Messages.AspectName_Contents), null, new TmfEventFieldAspect.IRootField() {
             @Override
-            public String getName() {
-                return Messages.getMessage(Messages.AspectName_Contents);
+            public @Nullable ITmfEventField getRootField(ITmfEvent event) {
+                return event.getContent();
             }
-
+        }) {
             @Override
             public String getHelpText() {
                 return Messages.getMessage(Messages.AspectHelpText_Contents);
             }
 
-            @Override
-            public String resolve(ITmfEvent event) {
-                String ret = event.getContent().toString();
-                return (ret == null ? EMPTY_STRING : ret);
-            }
         };
 
         /**
@@ -122,9 +135,8 @@ public interface ITmfEventAspect {
             }
 
             @Override
-            public String resolve(ITmfEvent event) {
-                String ret = event.getTrace().getName();
-                return (ret == null ? EMPTY_STRING : ret);
+            public @Nullable String resolve(ITmfEvent event) {
+                return event.getTrace().getName();
             }
         };
     }
@@ -167,5 +179,5 @@ public interface ITmfEventAspect {
      *            The event to process
      * @return The resulting tidbit of information for this event.
      */
-    Object resolve(ITmfEvent event);
+    @Nullable Object resolve(ITmfEvent event);
 }
This page took 0.026191 seconds and 5 git commands to generate.