diff --git a/Core/src/org/sleuthkit/autopsy/timeline/datamodel/EventBundle.java b/Core/src/org/sleuthkit/autopsy/timeline/datamodel/EventBundle.java index ba3333e7f7..7361bf5d88 100644 --- a/Core/src/org/sleuthkit/autopsy/timeline/datamodel/EventBundle.java +++ b/Core/src/org/sleuthkit/autopsy/timeline/datamodel/EventBundle.java @@ -47,7 +47,7 @@ public interface EventBundle> { Optional getParentBundle(); - default long getCount() { + default int getCount() { return getEventIDs().size(); } diff --git a/Core/src/org/sleuthkit/autopsy/timeline/datamodel/EventCluster.java b/Core/src/org/sleuthkit/autopsy/timeline/datamodel/EventCluster.java index 975b0cc40f..ac5a02d007 100644 --- a/Core/src/org/sleuthkit/autopsy/timeline/datamodel/EventCluster.java +++ b/Core/src/org/sleuthkit/autopsy/timeline/datamodel/EventCluster.java @@ -18,9 +18,9 @@ */ package org.sleuthkit.autopsy.timeline.datamodel; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.Sets; -import java.util.Collections; import java.util.Comparator; import java.util.Objects; import java.util.Optional; @@ -89,28 +89,28 @@ public class EventCluster implements EventBundle { /** * the set of ids of the clustered events */ - final private Set eventIDs; + final private ImmutableSet eventIDs; /** * the ids of the subset of clustered events that have at least one tag * applied to them */ - private final Set tagged; + private final ImmutableSet tagged; /** * the ids of the subset of clustered events that have at least one hash set * hit */ - private final Set hashHits; + private final ImmutableSet hashHits; private EventCluster(Interval spanningInterval, EventType type, Set eventIDs, Set hashHits, Set tagged, String description, DescriptionLoD lod, EventStripe parent) { this.span = spanningInterval; this.type = type; - this.hashHits = hashHits; - this.tagged = tagged; + this.hashHits = ImmutableSet.copyOf(hashHits); + this.tagged = ImmutableSet.copyOf(tagged); this.description = description; - this.eventIDs = eventIDs; + this.eventIDs = ImmutableSet.copyOf(eventIDs); this.lod = lod; this.parent = parent; } @@ -139,18 +139,21 @@ public class EventCluster implements EventBundle { } @Override - public Set getEventIDs() { - return Collections.unmodifiableSet(eventIDs); + @SuppressWarnings("ReturnOfCollectionOrArrayField") + public ImmutableSet getEventIDs() { + return eventIDs; } @Override - public Set getEventIDsWithHashHits() { - return Collections.unmodifiableSet(hashHits); + @SuppressWarnings("ReturnOfCollectionOrArrayField") + public ImmutableSet getEventIDsWithHashHits() { + return hashHits; } @Override - public Set getEventIDsWithTags() { - return Collections.unmodifiableSet(tagged); + @SuppressWarnings("ReturnOfCollectionOrArrayField") + public ImmutableSet getEventIDsWithTags() { + return tagged; } @Override diff --git a/Core/src/org/sleuthkit/autopsy/timeline/datamodel/EventStripe.java b/Core/src/org/sleuthkit/autopsy/timeline/datamodel/EventStripe.java index 7424727fcf..7a6bb4be42 100644 --- a/Core/src/org/sleuthkit/autopsy/timeline/datamodel/EventStripe.java +++ b/Core/src/org/sleuthkit/autopsy/timeline/datamodel/EventStripe.java @@ -19,13 +19,11 @@ package org.sleuthkit.autopsy.timeline.datamodel; import com.google.common.base.Preconditions; -import java.util.Collections; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSortedSet; import java.util.Comparator; -import java.util.HashSet; import java.util.Optional; -import java.util.Set; import java.util.SortedSet; -import java.util.TreeSet; import javax.annotation.concurrent.Immutable; import org.python.google.common.base.Objects; import org.sleuthkit.autopsy.timeline.datamodel.eventtype.EventType; @@ -50,7 +48,7 @@ public final class EventStripe implements EventBundle { private final EventCluster parent; - private final SortedSet clusters = new TreeSet<>(Comparator.comparing(EventCluster::getStartMillis)); + private final ImmutableSortedSet clusters; /** * the type of all the events @@ -70,59 +68,70 @@ public final class EventStripe implements EventBundle { /** * the set of ids of the events */ - private final Set eventIDs = new HashSet<>(); + private final ImmutableSet eventIDs; /** * the ids of the subset of events that have at least one tag applied to * them */ - private final Set tagged = new HashSet<>(); + private final ImmutableSet tagged; /** * the ids of the subset of events that have at least one hash set hit */ - private final Set hashHits = new HashSet<>(); + private final ImmutableSet hashHits; public EventStripe withParent(EventCluster parent) { - EventStripe eventStripe = new EventStripe(parent, this.type, this.description, this.lod); - eventStripe.clusters.addAll(clusters); - eventStripe.eventIDs.addAll(eventIDs); - eventStripe.tagged.addAll(tagged); - eventStripe.hashHits.addAll(hashHits); + EventStripe eventStripe = new EventStripe(parent, this.type, this.description, this.lod, clusters, eventIDs, tagged, hashHits); return eventStripe; } - private EventStripe(EventCluster parent, EventType type, String description, DescriptionLoD lod) { + private EventStripe(EventCluster parent, EventType type, String description, DescriptionLoD lod, SortedSet clusters, ImmutableSet eventIDs, ImmutableSet tagged, ImmutableSet hashHits) { this.parent = parent; this.type = type; this.description = description; this.lod = lod; + this.clusters = ImmutableSortedSet.copyOf(Comparator.comparing(EventCluster::getStartMillis), clusters); + + this.eventIDs = eventIDs; + this.tagged = tagged; + this.hashHits = hashHits; } public EventStripe(EventCluster cluster, EventCluster parent) { - clusters.add(cluster); + this.clusters = ImmutableSortedSet.orderedBy(Comparator.comparing(EventCluster::getStartMillis)) + .add(cluster).build(); type = cluster.getEventType(); description = cluster.getDescription(); lod = cluster.getDescriptionLoD(); - eventIDs.addAll(cluster.getEventIDs()); - tagged.addAll(cluster.getEventIDsWithTags()); - hashHits.addAll(cluster.getEventIDsWithHashHits()); + eventIDs = cluster.getEventIDs(); + tagged = cluster.getEventIDsWithTags(); + hashHits = cluster.getEventIDsWithHashHits(); this.parent = parent; } private EventStripe(EventStripe u, EventStripe v) { - clusters.addAll(u.clusters); - clusters.addAll(v.clusters); + clusters = ImmutableSortedSet.orderedBy(Comparator.comparing(EventCluster::getStartMillis)) + .addAll(u.getClusters()) + .addAll(v.getClusters()) + .build(); + type = u.getEventType(); description = u.getDescription(); lod = u.getDescriptionLoD(); - eventIDs.addAll(u.getEventIDs()); - eventIDs.addAll(v.getEventIDs()); - tagged.addAll(u.getEventIDsWithTags()); - tagged.addAll(v.getEventIDsWithTags()); - hashHits.addAll(u.getEventIDsWithHashHits()); - hashHits.addAll(v.getEventIDsWithHashHits()); + eventIDs = ImmutableSet.builder() + .addAll(u.getEventIDs()) + .addAll(v.getEventIDs()) + .build(); + tagged = ImmutableSet.builder() + .addAll(u.getEventIDsWithTags()) + .addAll(v.getEventIDsWithTags()) + .build(); + hashHits = ImmutableSet.builder() + .addAll(u.getEventIDsWithHashHits()) + .addAll(v.getEventIDsWithHashHits()) + .build(); parent = u.getParentBundle().orElse(v.getParentBundle().orElse(null)); } @@ -147,18 +156,21 @@ public final class EventStripe implements EventBundle { } @Override - public Set getEventIDs() { - return Collections.unmodifiableSet(eventIDs); + @SuppressWarnings("ReturnOfCollectionOrArrayField") + public ImmutableSet getEventIDs() { + return eventIDs; } @Override - public Set getEventIDsWithHashHits() { - return Collections.unmodifiableSet(hashHits); + @SuppressWarnings("ReturnOfCollectionOrArrayField") + public ImmutableSet getEventIDsWithHashHits() { + return hashHits; } @Override - public Set getEventIDsWithTags() { - return Collections.unmodifiableSet(tagged); + @SuppressWarnings("ReturnOfCollectionOrArrayField") + public ImmutableSet getEventIDsWithTags() { + return tagged; } @Override @@ -172,8 +184,9 @@ public final class EventStripe implements EventBundle { } @Override - public SortedSet< EventCluster> getClusters() { - return Collections.unmodifiableSortedSet(clusters); + @SuppressWarnings("ReturnOfCollectionOrArrayField") + public ImmutableSortedSet< EventCluster> getClusters() { + return clusters; } @Override diff --git a/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/EventClusterNode.java b/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/EventClusterNode.java index 8e5c600932..f348fd6873 100644 --- a/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/EventClusterNode.java +++ b/Core/src/org/sleuthkit/autopsy/timeline/ui/detailview/EventClusterNode.java @@ -143,7 +143,7 @@ final public class EventClusterNode extends EventBundleNodeBase