From: Alexandre Montplaisir Date: Wed, 9 Mar 2016 23:14:53 +0000 (-0500) Subject: common: Annotate TreeMultimap.create() X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=722d5c71417950463ee36dcd5d8bee0bd2cedd72;p=deliverable%2Ftracecompass.git common: Annotate TreeMultimap.create() 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 Reviewed-on: https://git.eclipse.org/r/68106 Reviewed-by: Hudson CI --- 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 index 0000000000..a6eb1d84fb --- /dev/null +++ b/common/org.eclipse.tracecompass.common.core/annotations/com/google/common/collect/TreeMultimap.eea @@ -0,0 +1,10 @@ +class com/google/common/collect/TreeMultimap +create + ()Lcom/google/common/collect/TreeMultimap; + ()L1com/google/common/collect/TreeMultimap; +create + (Lcom/google/common/collect/Multimap<+TK;+TV;>;)Lcom/google/common/collect/TreeMultimap; + (Lcom/google/common/collect/Multimap<+TK;+TV;>;)L1com/google/common/collect/TreeMultimap; +create + (Ljava/util/Comparator<-TK;>;Ljava/util/Comparator<-TV;>;)Lcom/google/common/collect/TreeMultimap; + (Ljava/util/Comparator<-TK;>;Ljava/util/Comparator<-TV;>;)L1com/google/common/collect/TreeMultimap; diff --git a/lttng/org.eclipse.tracecompass.lttng2.kernel.core/src/org/eclipse/tracecompass/internal/lttng2/kernel/core/analysis/vm/module/VirtualMachineCpuAnalysis.java b/lttng/org.eclipse.tracecompass.lttng2.kernel.core/src/org/eclipse/tracecompass/internal/lttng2/kernel/core/analysis/vm/module/VirtualMachineCpuAnalysis.java index 1289356064..fa41caba37 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.kernel.core/src/org/eclipse/tracecompass/internal/lttng2/kernel/core/analysis/vm/module/VirtualMachineCpuAnalysis.java +++ b/lttng/org.eclipse.tracecompass.lttng2.kernel.core/src/org/eclipse/tracecompass/internal/lttng2/kernel/core/analysis/vm/module/VirtualMachineCpuAnalysis.java @@ -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 map = NonNullUtils.checkNotNull(TreeMultimap.<@NonNull Integer, @NonNull ITmfStateInterval> create( - new Comparator() { - @Override - public int compare(@Nullable Integer arg0, @Nullable Integer arg1) { + final Multimap 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() { - @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; } diff --git a/statesystem/org.eclipse.tracecompass.segmentstore.core/src/org/eclipse/tracecompass/segmentstore/core/treemap/TreeMapStore.java b/statesystem/org.eclipse.tracecompass.segmentstore.core/src/org/eclipse/tracecompass/segmentstore/core/treemap/TreeMapStore.java index b358045beb..c32c8e9dcf 100644 --- a/statesystem/org.eclipse.tracecompass.segmentstore.core/src/org/eclipse/tracecompass/segmentstore/core/treemap/TreeMapStore.java +++ b/statesystem/org.eclipse.tracecompass.segmentstore.core/src/org/eclipse/tracecompass/segmentstore/core/treemap/TreeMapStore.java @@ -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; }