Remove unneeded checkNotNull() calls
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.ust.core / src / org / eclipse / tracecompass / lttng2 / ust / core / analysis / debuginfo / UstDebugInfoAnalysisModule.java
index 4892c3a62746c5d4425f898e9af3eeb582b4d0f0..7108e1de4e9c6aeb3f770f936927ac9475d507c8 100644 (file)
@@ -15,11 +15,14 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 import java.util.NavigableSet;
+import java.util.Optional;
 import java.util.Set;
 import java.util.TreeSet;
+import java.util.stream.Collectors;
 
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.tracecompass.internal.lttng2.ust.core.analysis.debuginfo.UstDebugInfoBinaryFile;
+import org.eclipse.tracecompass.internal.lttng2.ust.core.analysis.debuginfo.UstDebugInfoLoadedBinaryFile;
 import org.eclipse.tracecompass.internal.lttng2.ust.core.analysis.debuginfo.UstDebugInfoStateProvider;
 import org.eclipse.tracecompass.lttng2.ust.core.trace.LttngUstTrace;
 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
@@ -35,12 +38,7 @@ import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModul
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfUtils;
 
-import com.google.common.base.Function;
-import com.google.common.base.Optional;
-import com.google.common.base.Predicate;
-import com.google.common.collect.FluentIterable;
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Ordering;
 
 /**
  * Analysis to provide TMF Callsite information by mapping IP (instruction
@@ -78,7 +76,7 @@ public class UstDebugInfoAnalysisModule extends TmfStateSystemAnalysisModule {
     public Iterable<TmfAnalysisRequirement> getAnalysisRequirements() {
         // TODO specify actual requirements once the requirement-checking is
         // implemented. This analysis needs "ip" and "vpid" contexts.
-        return checkNotNull(Collections.EMPTY_SET);
+        return Collections.EMPTY_SET;
     }
 
     @Override
@@ -177,22 +175,24 @@ public class UstDebugInfoAnalysisModule extends TmfStateSystemAnalysisModule {
      * @return The {@link UstDebugInfoBinaryFile} object, containing both the binary's path
      *         and its build ID.
      */
-    @Nullable UstDebugInfoBinaryFile getMatchingFile(long ts, long vpid, long ip) {
+    @Nullable UstDebugInfoLoadedBinaryFile getMatchingFile(long ts, long vpid, long ip) {
         waitForCompletion();
         final ITmfStateSystem ss = checkNotNull(getStateSystem());
 
         List<Integer> possibleBaddrQuarks = ss.getQuarks(String.valueOf(vpid), "*"); //$NON-NLS-1$
 
         /* Get the most probable base address from all the known ones */
-        NavigableSet<Long> possibleBaddrs = FluentIterable.from(possibleBaddrQuarks)
-                .transform(new Function<Integer, Long>(){
-                    @Override
-                    public Long apply(@Nullable Integer quark) {
-                        String baddrStr = ss.getAttributeName(checkNotNull(quark).intValue());
-                        return checkNotNull(Long.valueOf(baddrStr));
-                    }
-                }).toSortedSet(Ordering.natural());
+        NavigableSet<Long> possibleBaddrs = possibleBaddrQuarks.stream()
+            .map(quark -> {
+                String baddrStr = ss.getAttributeName(quark.intValue());
+                return checkNotNull(Long.valueOf(baddrStr));
+            })
+            .collect(Collectors.toCollection(TreeSet::new));
+
         final Long potentialBaddr = possibleBaddrs.floor(ip);
+        if (potentialBaddr == null) {
+            return null;
+        }
 
         /* Make sure the 'ip' fits in the expected memory range */
         try {
@@ -214,14 +214,13 @@ public class UstDebugInfoAnalysisModule extends TmfStateSystemAnalysisModule {
              * library was loaded there at that time.
              */
             List<Integer> buildIds = ss.getSubAttributes(baddrQuark, false);
-            Optional<Integer> potentialBuildIdQuark = FluentIterable.from(buildIds).firstMatch(new Predicate<Integer>() {
-                @Override
-                public boolean apply(@Nullable Integer input) {
-                    int quark = checkNotNull(input).intValue();
+            Optional<Integer> potentialBuildIdQuark = buildIds.stream()
+                .filter(id -> {
+                    int quark = id.intValue();
                     ITmfStateValue value = fullState.get(quark).getStateValue();
                     return (!value.isNull());
-                }
-            });
+                })
+                .findFirst();
 
             if (!potentialBuildIdQuark.isPresent()) {
                 /* We didn't have the information after all. */
@@ -229,10 +228,12 @@ public class UstDebugInfoAnalysisModule extends TmfStateSystemAnalysisModule {
             }
 
             /* Ok, we have everything we need! Return the information. */
+            long baddr = Long.parseLong(ss.getAttributeName(baddrQuark));
+
             int buildIdQuark = potentialBuildIdQuark.get().intValue();
             String buildId = ss.getAttributeName(buildIdQuark);
             String filePath = fullState.get(buildIdQuark).getStateValue().unboxStr();
-            return new UstDebugInfoBinaryFile(filePath, buildId);
+            return new UstDebugInfoLoadedBinaryFile(baddr, filePath, buildId);
 
         } catch (AttributeNotFoundException e) {
             /* We're only using quarks we've checked for. */
@@ -242,5 +243,4 @@ public class UstDebugInfoAnalysisModule extends TmfStateSystemAnalysisModule {
         }
 
     }
-
 }
This page took 0.027003 seconds and 5 git commands to generate.