From 2e21b6d8848a9a5a2ca4cc4093d6663712afde87 Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Thu, 23 Jan 2014 14:27:21 -0500 Subject: [PATCH] tmf: Enforce non-null state sytem backends We now have a NullBackend for when we want a state system that discards past intervals. Change-Id: I8e62412ceac3c72c104cb512adb40b85b1ce9ce9 Signed-off-by: Alexandre Montplaisir Reviewed-on: https://git.eclipse.org/r/21018 Tested-by: Hudson CI Reviewed-by: Matthew Khouzam IP-Clean: Matthew Khouzam Tested-by: Matthew Khouzam --- .../tests/statesystem/VerifyHistoryFile.java | 5 ++--- .../tmf/core/statesystem/HistoryBuilder.java | 3 ++- .../tmf/core/statesystem/StateSystem.java | 5 +++-- .../tmf/core/statesystem/TransientState.java | 21 +++++++------------ 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/VerifyHistoryFile.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/VerifyHistoryFile.java index d3ae77139f..a0d61cbd54 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/VerifyHistoryFile.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/statesystem/VerifyHistoryFile.java @@ -40,7 +40,6 @@ public class VerifyHistoryFile { public static final String pathToHistoryFile = ""; private static File htFile; - private static IStateHistoryBackend htBackend; private static ITmfStateSystem ss; private static long startTime; @@ -51,8 +50,8 @@ public class VerifyHistoryFile { TimeRangeException, AttributeNotFoundException, StateSystemDisposedException { htFile = new File(pathToHistoryFile); - htBackend = new HistoryTreeBackend(htFile, ITmfStateProvider.IGNORE_PROVIDER_VERSION); - ss = HistoryBuilder.openExistingHistory(htBackend); + IStateHistoryBackend backend = new HistoryTreeBackend(htFile, ITmfStateProvider.IGNORE_PROVIDER_VERSION); + ss = HistoryBuilder.openExistingHistory(backend); startTime = ss.getStartTime(); endTime = ss.getCurrentEndTime(); diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/HistoryBuilder.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/HistoryBuilder.java index c80841ce15..30db8416fa 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/HistoryBuilder.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/HistoryBuilder.java @@ -14,6 +14,7 @@ package org.eclipse.linuxtools.internal.tmf.core.statesystem; import java.io.IOException; +import org.eclipse.jdt.annotation.NonNull; import org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.IStateHistoryBackend; import org.eclipse.linuxtools.tmf.core.component.TmfComponent; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; @@ -106,7 +107,7 @@ public class HistoryBuilder extends TmfComponent { * If there was something wrong. */ public static ITmfStateSystemBuilder openExistingHistory( - IStateHistoryBackend hb) throws IOException { + @NonNull IStateHistoryBackend hb) throws IOException { return new StateSystem(hb, false); } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java index 5af4cd6a5a..769188ef78 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateSystem.java @@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jdt.annotation.NonNull; import org.eclipse.linuxtools.internal.tmf.core.Activator; import org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.IStateHistoryBackend; import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException; @@ -69,7 +70,7 @@ public class StateSystem implements ITmfStateSystemBuilder { * @param backend * Back-end plugin to use */ - public StateSystem(IStateHistoryBackend backend) { + public StateSystem(@NonNull IStateHistoryBackend backend) { this.backend = backend; this.transState = new TransientState(backend); this.attributeTree = new AttributeTree(this); @@ -86,7 +87,7 @@ public class StateSystem implements ITmfStateSystemBuilder { * @throws IOException * If there was a problem creating the new history file */ - public StateSystem(IStateHistoryBackend backend, boolean newFile) + public StateSystem(@NonNull IStateHistoryBackend backend, boolean newFile) throws IOException { this.backend = backend; this.transState = new TransientState(backend); diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/TransientState.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/TransientState.java index 395e79eef1..c86b90641a 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/TransientState.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/TransientState.java @@ -16,6 +16,7 @@ import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; +import org.eclipse.jdt.annotation.NonNull; import org.eclipse.linuxtools.internal.tmf.core.statesystem.backends.IStateHistoryBackend; import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException; import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException; @@ -23,8 +24,8 @@ import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException; import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval; import org.eclipse.linuxtools.tmf.core.interval.TmfStateInterval; import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue; -import org.eclipse.linuxtools.tmf.core.statevalue.TmfStateValue; import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue.Type; +import org.eclipse.linuxtools.tmf.core.statevalue.TmfStateValue; /** * The Transient State is used to build intervals from punctual state changes. @@ -41,7 +42,7 @@ import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue.Type; public class TransientState { /* Indicates where to insert state changes that we generate */ - private final IStateHistoryBackend backend; + @NonNull private final IStateHistoryBackend backend; private boolean isActive; private long latestTime; @@ -56,18 +57,14 @@ public class TransientState { * @param backend * The back-end in which to insert the generated state intervals */ - public TransientState(IStateHistoryBackend backend) { + public TransientState(@NonNull IStateHistoryBackend backend) { this.backend = backend; isActive = true; ongoingStateInfo = new ArrayList<>(); ongoingStateStartTimes = new ArrayList<>(); stateValueTypes = new ArrayList<>(); - if (backend != null) { - latestTime = backend.getStartTime(); - } else { - latestTime = 0; - } + latestTime = backend.getStartTime(); } /** @@ -186,11 +183,7 @@ public class TransientState { ongoingStateInfo.add(TmfStateValue.nullValue()); stateValueTypes.add(Type.NULL); - if (backend == null) { - ongoingStateStartTimes.add(0L); - } else { - ongoingStateStartTimes.add(backend.getStartTime()); - } + ongoingStateStartTimes.add(backend.getStartTime()); } /** @@ -269,7 +262,7 @@ public class TransientState { return; } - if (backend != null && ongoingStateStartTimes.get(quark) < eventTime) { + if (ongoingStateStartTimes.get(quark) < eventTime) { /* * These two conditions are necessary to create an interval and * update ongoingStateInfo. -- 2.34.1