common: Annotate TreeMultimap.create()
authorAlexandre Montplaisir <alexmonthy@efficios.com>
Wed, 9 Mar 2016 23:14:53 +0000 (18:14 -0500)
committerAlexandre Montplaisir <alexmonthy@efficios.com>
Fri, 11 Mar 2016 17:32:35 +0000 (12:32 -0500)
All variants of this method return a new map, so it can be
annotated @NonNull.

Remove now-unnecessary checkNotNull() checks where this was called.

While at it, rewrote some comparator definitions in more succinct
lambda expressions.

Change-Id: Ic7a78eb38b9cf3fd2b8e79ab385d73c5d4cc2961
Signed-off-by: Alexandre Montplaisir <alexmonthy@efficios.com>
Reviewed-on: https://git.eclipse.org/r/68106
Reviewed-by: Hudson CI
common/org.eclipse.tracecompass.common.core/annotations/com/google/common/collect/TreeMultimap.eea [new file with mode: 0644]
lttng/org.eclipse.tracecompass.lttng2.kernel.core/src/org/eclipse/tracecompass/internal/lttng2/kernel/core/analysis/vm/module/VirtualMachineCpuAnalysis.java
statesystem/org.eclipse.tracecompass.segmentstore.core/src/org/eclipse/tracecompass/segmentstore/core/treemap/TreeMapStore.java

diff --git a/common/org.eclipse.tracecompass.common.core/annotations/com/google/common/collect/TreeMultimap.eea b/common/org.eclipse.tracecompass.common.core/annotations/com/google/common/collect/TreeMultimap.eea
new file mode 100644 (file)
index 0000000..a6eb1d8
--- /dev/null
@@ -0,0 +1,10 @@
+class com/google/common/collect/TreeMultimap
+create
+ <K::Ljava/lang/Comparable;V::Ljava/lang/Comparable;>()Lcom/google/common/collect/TreeMultimap<TK;TV;>;
+ <K::Ljava/lang/Comparable;V::Ljava/lang/Comparable;>()L1com/google/common/collect/TreeMultimap<TK;TV;>;
+create
+ <K::Ljava/lang/Comparable;V::Ljava/lang/Comparable;>(Lcom/google/common/collect/Multimap<+TK;+TV;>;)Lcom/google/common/collect/TreeMultimap<TK;TV;>;
+ <K::Ljava/lang/Comparable;V::Ljava/lang/Comparable;>(Lcom/google/common/collect/Multimap<+TK;+TV;>;)L1com/google/common/collect/TreeMultimap<TK;TV;>;
+create
+ <K:Ljava/lang/Object;V:Ljava/lang/Object;>(Ljava/util/Comparator<-TK;>;Ljava/util/Comparator<-TV;>;)Lcom/google/common/collect/TreeMultimap<TK;TV;>;
+ <K:Ljava/lang/Object;V:Ljava/lang/Object;>(Ljava/util/Comparator<-TK;>;Ljava/util/Comparator<-TV;>;)L1com/google/common/collect/TreeMultimap<TK;TV;>;
index 1289356064462f360fab843d83adfcbe8bf75a4c..fa41caba3795bba238d8f424b95b2bb0989c72a4 100644 (file)
@@ -21,7 +21,6 @@ import java.util.Set;
 
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.tracecompass.analysis.os.linux.core.kernelanalysis.KernelAnalysisModule;
 import org.eclipse.tracecompass.analysis.os.linux.core.kernelanalysis.KernelThreadInformationProvider;
 import org.eclipse.tracecompass.common.core.NonNullUtils;
@@ -113,41 +112,26 @@ public class VirtualMachineCpuAnalysis extends TmfStateSystemAnalysisModule {
          * Create the multimap for threads with the appropriate comparator
          * objects for keys and values
          */
-        final Multimap<Integer, ITmfStateInterval> map = NonNullUtils.checkNotNull(TreeMultimap.<@NonNull Integer, @NonNull ITmfStateInterval> create(
-                new Comparator<Integer>() {
-                    @Override
-                    public int compare(@Nullable Integer arg0, @Nullable Integer arg1) {
+        final Multimap<Integer, ITmfStateInterval> map = TreeMultimap.create(
+                /* Key comparator. Keys do not have to be sorted, just use natural sorting*/
+                Comparator.naturalOrder(),
+
+                /* Value comparator */
+                (arg0, arg1) -> {
+                    if (arg1.getStateValue() == VCPU_PREEMPT_VALUE && arg0.getStateValue() != VCPU_PREEMPT_VALUE) {
                         /*
-                         * Keys do not have to be sorted, just use natural
-                         * sorting
+                         * For VCPU_PREEMPT state values, the state has to be
+                         * after any other state that it overlaps, because those
+                         * intervals usually decorate the other intervals.
                          */
-                        if (arg0 == null || arg1 == null) {
+                        if (((Long) arg0.getEndTime()).compareTo(arg1.getStartTime()) < 0) {
                             return -1;
                         }
-                        return arg0.compareTo(arg1);
-                    }
-                }, new Comparator<ITmfStateInterval>() {
-                    @Override
-                    public int compare(@Nullable ITmfStateInterval arg0, @Nullable ITmfStateInterval arg1) {
-                        if (arg0 == null || arg1 == null) {
-                            return 0;
-                        }
-                        if (arg1.getStateValue() == VCPU_PREEMPT_VALUE && arg0.getStateValue() != VCPU_PREEMPT_VALUE) {
-                            /*
-                             * For VCPU_PREEMPT state values, the state has to
-                             * be after any other state that it overlaps,
-                             * because those intervals usually decorate the
-                             * other intervals.
-                             */
-                            if (((Long) arg0.getEndTime()).compareTo(arg1.getStartTime()) < 0) {
-                                return -1;
-                            }
-                            return ((Long) arg0.getStartTime()).compareTo(arg1.getEndTime());
-                        }
-                        /* Otherwise, we use ordering by start time */
-                        return (((Long) arg0.getStartTime()).compareTo(arg1.getStartTime()));
+                        return ((Long) arg0.getStartTime()).compareTo(arg1.getEndTime());
                     }
-                }));
+                    /* Otherwise, we use ordering by start time */
+                    return (((Long) arg0.getStartTime()).compareTo(arg1.getStartTime()));
+                });
         return map;
     }
 
index b358045bebd6ea4442c97a34e5561f50eae599fc..c32c8e9dcfc716095d3d1c211ec200342793b955 100644 (file)
@@ -80,13 +80,13 @@ public class TreeMapStore<@NonNull E extends ISegment> implements ISegmentStore<
          * The same is done for the end times index, but swapping the first two
          * comparators instead.
          */
-        fStartTimesIndex = checkNotNull(TreeMultimap.create(
+        fStartTimesIndex = TreeMultimap.create(
                 SegmentComparators.LONG_COMPARATOR,
-                Ordering.from(SegmentComparators.INTERVAL_END_COMPARATOR).compound(Ordering.natural())));
+                Ordering.from(SegmentComparators.INTERVAL_END_COMPARATOR).compound(Ordering.natural()));
 
-        fEndTimesIndex = checkNotNull(TreeMultimap.create(
+        fEndTimesIndex = TreeMultimap.create(
                 SegmentComparators.LONG_COMPARATOR,
-                Ordering.from(SegmentComparators.INTERVAL_START_COMPARATOR).compound(Ordering.natural())));
+                Ordering.from(SegmentComparators.INTERVAL_START_COMPARATOR).compound(Ordering.natural()));
 
         fSize = 0;
     }
This page took 0.027391 seconds and 5 git commands to generate.