TMF: Make the ITmfEvent#getTimestamp() return NonNull
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Tue, 10 Feb 2015 21:33:45 +0000 (16:33 -0500)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Thu, 12 Feb 2015 20:27:51 +0000 (15:27 -0500)
And all the required NonNull annotations to fix all the warnings

Change-Id: If064c2ca2da96bbeb6c143f48e5b965e34b91314
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/41239
Reviewed-by: Hudson CI
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
Tested-by: Patrick Tasse <patrick.tasse@gmail.com>
org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/event/TmfEventTest.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/event/ITmfEvent.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/event/TmfEvent.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomEvent.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/timestamp/TmfTimestamp.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/trace/experiment/TmfExperiment.java
org.eclipse.tracecompass.tmf.ctf.core.tests/src/org/eclipse/tracecompass/tmf/ctf/core/tests/event/CtfTmfLostEventsTest.java
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/events/TmfEventPropertySource.java

index 1b7c7526e9b2a098316bdb13ed3f737fd3d17196..07f47b5c3140860aad486c538f24ef3ee00fa728 100644 (file)
@@ -92,7 +92,7 @@ public class TmfEventTest {
         final ITmfEvent event = new TmfEvent(fTrace, ITmfContext.UNKNOWN_RANK, null, null, null);
         assertNotNull("getTrace", event.getTrace());
         assertEquals("getRank", ITmfContext.UNKNOWN_RANK, event.getRank());
-        assertNull("getTimestamp", event.getTimestamp());
+        assertEquals("getTimestamp", TmfTimestamp.ZERO, event.getTimestamp());
         assertNull("getType", event.getType());
         assertNull("getContent", event.getContent());
     }
index b6ec6710a0fd2701deb5b63c3a8f0c6870f2fe4e..6f39e5c30efc57ce9ecb4c2a901db08408e5bd97 100644 (file)
@@ -55,7 +55,7 @@ public interface ITmfEvent extends IAdaptable {
      * @return the event timestamp
      * @since 2.0
      */
-    ITmfTimestamp getTimestamp();
+    @NonNull ITmfTimestamp getTimestamp();
 
     /**
      * @return the event type
index 91a3101864cf53b2fe121db977571cf5c4ea91f9..1fc6f77f4966677fdfa641be34c2c23f5ff1496d 100644 (file)
@@ -16,6 +16,7 @@ package org.eclipse.tracecompass.tmf.core.event;
 import org.eclipse.core.runtime.PlatformObject;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 
@@ -38,7 +39,7 @@ public class TmfEvent extends PlatformObject implements ITmfEvent {
 
     private final ITmfTrace fTrace;
     private final long fRank;
-    private final ITmfTimestamp fTimestamp;
+    private final @NonNull ITmfTimestamp fTimestamp;
     private final ITmfEventType fType;
     private final ITmfEventField fContent;
 
@@ -82,7 +83,11 @@ public class TmfEvent extends PlatformObject implements ITmfEvent {
             final ITmfEventField content) {
         fTrace = trace;
         fRank = rank;
-        fTimestamp = timestamp;
+        if (timestamp != null) {
+            fTimestamp = timestamp;
+        } else {
+            fTimestamp = TmfTimestamp.ZERO;
+        }
         fType = type;
         fContent = content;
     }
@@ -146,7 +151,7 @@ public class TmfEvent extends PlatformObject implements ITmfEvent {
         int result = 1;
         result = prime * result + ((fTrace == null) ? 0 : fTrace.hashCode());
         result = prime * result + (int) (fRank ^ (fRank >>> 32));
-        result = prime * result + ((fTimestamp == null) ? 0 : fTimestamp.hashCode());
+        result = prime * result + fTimestamp.hashCode();
         result = prime * result + ((fType == null) ? 0 : fType.hashCode());
         result = prime * result + ((fContent == null) ? 0 : fContent.hashCode());
         return result;
@@ -174,11 +179,7 @@ public class TmfEvent extends PlatformObject implements ITmfEvent {
         if (fRank != other.fRank) {
             return false;
         }
-        if (fTimestamp == null) {
-            if (other.fTimestamp != null) {
-                return false;
-            }
-        } else if (!fTimestamp.equals(other.fTimestamp)) {
+        if (!fTimestamp.equals(other.fTimestamp)) {
             return false;
         }
         if (fType == null) {
index f8f03f71e60ed28a025414c050aa733b832636f3..4076e55c6c78aed7958f01cd93b2ec80480e6191 100644 (file)
@@ -45,7 +45,7 @@ public class CustomEvent extends TmfEvent {
     protected static final String NO_MESSAGE = ""; //$NON-NLS-1$
 
     /** Replacement for the super-class' timestamp field */
-    private ITmfTimestamp customEventTimestamp;
+    private @NonNull ITmfTimestamp customEventTimestamp;
 
     /** Replacement for the super-class' content field */
     private ITmfEventField customEventContent;
@@ -71,6 +71,7 @@ public class CustomEvent extends TmfEvent {
         super(null, ITmfContext.UNKNOWN_RANK, null, null, null);
         fDefinition = definition;
         fData = new HashMap<>();
+        customEventTimestamp = TmfTimestamp.ZERO;
     }
 
     /**
@@ -112,7 +113,11 @@ public class CustomEvent extends TmfEvent {
         fData = new HashMap<>();
 
         /* Set our overridden fields */
-        customEventTimestamp = timestamp;
+        if (timestamp == null) {
+            customEventTimestamp = TmfTimestamp.ZERO;
+        } else {
+            customEventTimestamp = timestamp;
+        }
         customEventContent = null;
         customEventType = type;
     }
@@ -149,7 +154,7 @@ public class CustomEvent extends TmfEvent {
      * @param timestamp
      *            The new timestamp
      */
-    protected void setTimestamp(ITmfTimestamp timestamp) {
+    protected void setTimestamp(@NonNull ITmfTimestamp timestamp) {
         customEventTimestamp = timestamp;
     }
 
@@ -235,7 +240,7 @@ public class CustomEvent extends TmfEvent {
         final int prime = 31;
         int result = super.hashCode();
         result = prime * result + ((fDefinition == null) ? 0 : fDefinition.hashCode());
-        result = prime * result + ((customEventTimestamp == null) ? 0 : customEventTimestamp.hashCode());
+        result = prime * result + customEventTimestamp.hashCode();
         result = prime * result + ((customEventContent == null) ? 0 : customEventContent.hashCode());
         result = prime * result + ((customEventType == null) ? 0 : customEventType.hashCode());
         return result;
@@ -261,11 +266,7 @@ public class CustomEvent extends TmfEvent {
             return false;
         }
 
-        if (customEventTimestamp == null) {
-            if (other.customEventTimestamp != null) {
-                return false;
-            }
-        } else if (!customEventTimestamp.equals(other.customEventTimestamp)) {
+        if (!customEventTimestamp.equals(other.customEventTimestamp)) {
             return false;
         }
 
index 4e39d52055c7914983b0142156c8a4956fcc6be4..b754a8add549062a3e68872105dae14ac857ebe6 100644 (file)
@@ -17,6 +17,8 @@ package org.eclipse.tracecompass.tmf.core.timestamp;
 
 import java.nio.ByteBuffer;
 
+import org.eclipse.jdt.annotation.NonNull;
+
 /**
  * A generic timestamp implementation. The timestamp is represented by the
  * tuple { value, scale, precision }. By default, timestamps are scaled in
@@ -34,29 +36,19 @@ public class TmfTimestamp implements ITmfTimestamp {
     /**
      * The beginning of time
      */
-    public static final ITmfTimestamp BIG_BANG =
+    public static final @NonNull ITmfTimestamp BIG_BANG =
             new TmfTimestamp(Long.MIN_VALUE, Integer.MAX_VALUE);
 
     /**
      * The end of time
      */
-    public static final ITmfTimestamp BIG_CRUNCH =
+    public static final @NonNull ITmfTimestamp BIG_CRUNCH =
             new TmfTimestamp(Long.MAX_VALUE, Integer.MAX_VALUE);
 
-    /**
-     * A more practical definition of "beginning of time"
-     */
-    public static final ITmfTimestamp PROJECT_IS_FUNDED = BIG_BANG;
-
-    /**
-     * A more practical definition of "end of time"
-     */
-    public static final ITmfTimestamp PROJECT_IS_CANNED = BIG_CRUNCH;
-
     /**
      * Zero
      */
-    public static final ITmfTimestamp ZERO =
+    public static final @NonNull ITmfTimestamp ZERO =
             new TmfTimestamp(0, 0);
 
     // ------------------------------------------------------------------------
index d77567335268918ccc33006d4dcdb68974736e0c..8af64480d1cca6f3cbc465651f43c89343a6f772 100644 (file)
@@ -419,7 +419,7 @@ public class TmfExperiment extends TmfTrace implements ITmfPersistentlyIndexable
         for (int i = 0; i < length; i++) {
             final ITmfEvent event = expContext.getEvent(i);
 
-            if (event != null && event.getTimestamp() != null) {
+            if (event != null) {
                 final ITmfTimestamp otherTS = event.getTimestamp();
                 if (otherTS.compareTo(timestamp) < 0) {
                     trace = i;
index 04e4fd7ecaf3f9f1bbd8ec4918691f80eeb731c7..7d1af7dd0650531c7bbc0132b05e4f42a9d2ec2c 100644 (file)
@@ -212,7 +212,7 @@ public class CtfTmfLostEventsTest {
 
         public OneEventRequestPerTs(ITmfTimestamp ts) {
             super(CtfTmfEvent.class,
-                    new TmfTimeRange(ts, TmfTimestamp.PROJECT_IS_CANNED),
+                    new TmfTimeRange(ts, TmfTimestamp.BIG_CRUNCH),
                     0, 1, ExecutionType.FOREGROUND);
         }
 
index 94a0ed37c97e3fb1dcbdaef59aecdfdc7bcf455a..eb90396c2cce968f646784ff6756baad6660d1c9 100644 (file)
@@ -306,7 +306,7 @@ public class TmfEventPropertySource implements IPropertySource {
 
     @Override
     public Object getPropertyValue(Object id) {
-        if (id.equals(ID_TIMESTAMP) && fEvent.getTimestamp() != null) {
+        if (id.equals(ID_TIMESTAMP)) {
             return new TimestampPropertySource(fEvent.getTimestamp());
         } else if (id.equals(ID_TYPE) && fEvent.getType() != null) {
             return fEvent.getType().toString();
This page took 0.033208 seconds and 5 git commands to generate.