From 567f9c59bb0b6b03a2664b3a2af71bc4c4d9778c Mon Sep 17 00:00:00 2001 From: millmanorama Date: Wed, 3 Apr 2019 14:06:16 +0200 Subject: [PATCH 1/2] fix merge --- .../ui/detailview/datamodel/EventCluster.java | 6 +++--- .../timeline/ui/detailview/datamodel/EventStripe.java | 11 +++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/datamodel/EventCluster.java b/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/datamodel/EventCluster.java index f4f7419a82..20b5eb70a5 100644 --- a/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/datamodel/EventCluster.java +++ b/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/datamodel/EventCluster.java @@ -99,9 +99,9 @@ public class EventCluster implements MultiEvent { Interval spanningInterval = IntervalUtils.span(cluster1.span, cluster2.span); - Set idsUnion = Sets.union(cluster2.getEventIDs(), cluster2.getEventIDs()); - Set hashHitsUnion = Sets.union(cluster2.getEventIDsWithHashHits(), cluster2.getEventIDsWithHashHits()); - Set taggedUnion = Sets.union(cluster2.getEventIDsWithTags(), cluster2.getEventIDsWithTags()); + Set idsUnion = Sets.union(cluster1.getEventIDs(), cluster2.getEventIDs()); + Set hashHitsUnion = Sets.union(cluster1.getEventIDsWithHashHits(), cluster2.getEventIDsWithHashHits()); + Set taggedUnion = Sets.union(cluster1.getEventIDsWithTags(), cluster2.getEventIDsWithTags()); return new EventCluster(spanningInterval, cluster1.getEventType(), idsUnion, hashHitsUnion, taggedUnion, diff --git a/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/datamodel/EventStripe.java b/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/datamodel/EventStripe.java index 3667e150a4..25fc5ef92a 100644 --- a/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/datamodel/EventStripe.java +++ b/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/datamodel/EventStripe.java @@ -90,7 +90,7 @@ public final class EventStripe implements MultiEvent { return new EventStripe(parent, this.type, this.description, this.lod, clusters, eventIDs, tagged, hashHits); } - private EventStripe(EventCluster parent, EventType type, String description, + private EventStripe(EventCluster parent, EventType type, String description, DescriptionLoD lod, SortedSet clusters, Set eventIDs, Set tagged, Set hashHits) { this.parent = parent; @@ -107,7 +107,6 @@ public final class EventStripe implements MultiEvent { public EventStripe(EventCluster cluster) { this.clusters = copyAsSortedSet(singleton(cluster.withParent(this)), comparing(EventCluster::getStartMillis)); - type = cluster.getEventType(); description = cluster.getDescription(); @@ -119,14 +118,14 @@ public final class EventStripe implements MultiEvent { } private EventStripe(EventStripe stripeA, EventStripe stripeB) { - clusters = copyAsSortedSet(Sets.union(stripeB.getClusters(), stripeB.getClusters()), comparing(EventCluster::getStartMillis)); + clusters = copyAsSortedSet(Sets.union(stripeA.getClusters(), stripeB.getClusters()), comparing(EventCluster::getStartMillis)); type = stripeA.getEventType(); description = stripeA.getDescription(); lod = stripeA.getDescriptionLoD(); - eventIDs = Sets.union(stripeB.getEventIDs(), stripeB.getEventIDs()); - tagged = Sets.union(stripeB.getEventIDsWithTags(), stripeB.getEventIDsWithTags()); - hashHits = Sets.union(stripeB.getEventIDsWithHashHits(), stripeB.getEventIDsWithHashHits()); + eventIDs = Sets.union(stripeA.getEventIDs(), stripeB.getEventIDs()); + tagged = Sets.union(stripeA.getEventIDsWithTags(), stripeB.getEventIDsWithTags()); + hashHits = Sets.union(stripeA.getEventIDsWithHashHits(), stripeB.getEventIDsWithHashHits()); parent = stripeA.getParent().orElse(stripeB.getParent().orElse(null)); } From 55eecf450864605ffe9f05f65766f3738e47b7a8 Mon Sep 17 00:00:00 2001 From: millmanorama Date: Wed, 3 Apr 2019 15:08:48 +0200 Subject: [PATCH 2/2] fix getClusters() by making sorted set with explicit comparator. --- .../datamodel/DetailsViewModel.java | 21 ++++++++++++++++++- .../ui/detailview/datamodel/EventCluster.java | 4 ++-- .../ui/detailview/datamodel/EventStripe.java | 13 ++---------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/datamodel/DetailsViewModel.java b/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/datamodel/DetailsViewModel.java index 5fe5d6205f..650e237675 100644 --- a/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/datamodel/DetailsViewModel.java +++ b/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/datamodel/DetailsViewModel.java @@ -26,11 +26,15 @@ import com.google.common.eventbus.Subscribe; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Collection; +import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.logging.Level; @@ -254,7 +258,7 @@ final public class DetailsViewModel { .sorted(new DetailViewEvent.StartComparator()) .iterator(); EventCluster current = iterator.next(); - + //JM Todo: maybe we can collect all clusters to merge in one go, rather than piece by piece for performance. while (iterator.hasNext()) { EventCluster next = iterator.next(); @@ -287,4 +291,19 @@ final public class DetailsViewModel { .sorted(new DetailViewEvent.StartComparator()) .collect(Collectors.toList()); } + + /** Make a sorted copy of the given set using the given comparator to sort + * it. + * + * @param The type of elements in the set. + * @param setA The set of elements to copy into the new sorted set. + * @param comparator The comparator to sort the new set by. + * + * @return A sorted copy of the given set. + */ + static SortedSet copyAsSortedSet(Collection setA, Comparator comparator) { + TreeSet treeSet = new TreeSet<>(comparator); + treeSet.addAll(setA); + return treeSet; + } } diff --git a/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/datamodel/EventCluster.java b/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/datamodel/EventCluster.java index 20b5eb70a5..c675ab86d8 100644 --- a/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/datamodel/EventCluster.java +++ b/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/datamodel/EventCluster.java @@ -21,11 +21,11 @@ package org.sleuthkit.autopsy.timeline.ui.detailview.datamodel; import com.google.common.collect.Sets; import static java.util.Collections.emptySet; import static java.util.Collections.singleton; +import java.util.Comparator; import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.SortedSet; -import java.util.TreeSet; import org.joda.time.Interval; import org.sleuthkit.autopsy.timeline.utils.IntervalUtils; import org.sleuthkit.datamodel.DescriptionLoD; @@ -222,7 +222,7 @@ public class EventCluster implements MultiEvent { @Override public SortedSet getClusters() { - return new TreeSet<>(singleton(this)); + return DetailsViewModel.copyAsSortedSet(singleton(this), Comparator.comparing(cluster -> true)); } @Override diff --git a/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/datamodel/EventStripe.java b/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/datamodel/EventStripe.java index 25fc5ef92a..c8d66d24f3 100644 --- a/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/datamodel/EventStripe.java +++ b/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/datamodel/EventStripe.java @@ -20,15 +20,12 @@ package org.sleuthkit.autopsy.timeline.ui.detailview.datamodel; import com.google.common.base.Preconditions; import com.google.common.collect.Sets; -import java.util.Collection; import static java.util.Collections.singleton; -import java.util.Comparator; import static java.util.Comparator.comparing; import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.SortedSet; -import java.util.TreeSet; import org.sleuthkit.datamodel.DescriptionLoD; import org.sleuthkit.datamodel.timeline.EventType; @@ -105,7 +102,7 @@ public final class EventStripe implements MultiEvent { } public EventStripe(EventCluster cluster) { - this.clusters = copyAsSortedSet(singleton(cluster.withParent(this)), + this.clusters = DetailsViewModel.copyAsSortedSet(singleton(cluster.withParent(this)), comparing(EventCluster::getStartMillis)); type = cluster.getEventType(); @@ -118,7 +115,7 @@ public final class EventStripe implements MultiEvent { } private EventStripe(EventStripe stripeA, EventStripe stripeB) { - clusters = copyAsSortedSet(Sets.union(stripeA.getClusters(), stripeB.getClusters()), comparing(EventCluster::getStartMillis)); + clusters = DetailsViewModel.copyAsSortedSet(Sets.union(stripeA.getClusters(), stripeB.getClusters()), comparing(EventCluster::getStartMillis)); type = stripeA.getEventType(); description = stripeA.getDescription(); @@ -231,10 +228,4 @@ public final class EventStripe implements MultiEvent { return Objects.equals(this.eventIDs, other.eventIDs); } - private static SortedSet copyAsSortedSet(Collection setA, Comparator comparator) { - - TreeSet treeSet = new TreeSet<>(comparator); - treeSet.addAll(setA); - return treeSet; - } }