Merge pull request #4672 from millmanorama/1216-drop-immutablesets

1216 fix merge
This commit is contained in:
Richard Cordovano 2019-04-04 11:19:22 -04:00 committed by GitHub
commit cd2e7159a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 19 deletions

View File

@ -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 <X> 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 <X> SortedSet<X> copyAsSortedSet(Collection<X> setA, Comparator<X> comparator) {
TreeSet<X> treeSet = new TreeSet<>(comparator);
treeSet.addAll(setA);
return treeSet;
}
}

View File

@ -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<EventStripe> {
@Override
public SortedSet<EventCluster> getClusters() {
return new TreeSet<>(singleton(this));
return DetailsViewModel.copyAsSortedSet(singleton(this), Comparator.comparing(cluster -> true));
}
@Override

View File

@ -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<EventCluster> {
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<EventCluster> clusters,
Set<Long> eventIDs, Set<Long> tagged, Set<Long> hashHits) {
this.parent = parent;
@ -105,9 +102,8 @@ public final class EventStripe implements MultiEvent<EventCluster> {
}
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<EventCluster> {
}
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<EventCluster> {
return Objects.equals(this.eventIDs, other.eventIDs);
}
private static <X> SortedSet<X> copyAsSortedSet(Collection<X> setA, Comparator<X> comparator) {
TreeSet<X> treeSet = new TreeSet<>(comparator);
treeSet.addAll(setA);
return treeSet;
}
}