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 3667e150a4..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; @@ -90,7 +87,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; @@ -105,9 +102,8 @@ 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(); description = cluster.getDescription(); @@ -119,14 +115,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 = DetailsViewModel.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)); } @@ -232,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; - } }