From 2d2ea329f23b4972d78e58625b09ab4ea097823a Mon Sep 17 00:00:00 2001 From: millmanorama Date: Thu, 20 Jul 2017 16:29:12 +0200 Subject: [PATCH 1/2] don't make the nodes at the same time as the keys, use addAll rather than adding each key to list. --- .../autopsy/datamodel/KeywordHits.java | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/KeywordHits.java b/Core/src/org/sleuthkit/autopsy/datamodel/KeywordHits.java index 9214652223..477ca2fa7b 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/KeywordHits.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/KeywordHits.java @@ -33,6 +33,7 @@ import java.util.Observable; import java.util.Observer; import java.util.Set; import java.util.logging.Level; +import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; import org.openide.nodes.ChildFactory; import org.openide.nodes.Children; @@ -95,6 +96,10 @@ public class KeywordHits implements AutopsyVisitableItem { + " OR attribute_type_id = " + BlackboardAttribute.ATTRIBUTE_TYPE.TSK_KEYWORD_REGEXP.getTypeID()//NON-NLS + ")"; //NON-NLS + static private boolean isOnlyDefaultInstance(List instances) { + return (instances.size() == 1) && (instances.get(0).equals(DEFAULT_INSTANCE_NAME)); + } + public KeywordHits(SleuthkitCase skCase) { this.skCase = skCase; keywordResults = new KeywordResults(); @@ -265,7 +270,6 @@ public class KeywordHits implements AutopsyVisitableItem { addRegExpToList(listMap, reg, word, id); } } else {//single term - if ("1".equals(kwType) || reg == null) { //literal, substring or exact /* * Substring, treated same as exact match. "1" is @@ -626,9 +630,8 @@ public class KeywordHits implements AutopsyVisitableItem { @Override public boolean isLeafTypeNode() { - List instances = keywordResults.getKeywordInstances(setName, keyword); // is this an exact/substring match (i.e. did we use the DEFAULT name)? - return instances.size() == 1 && instances.get(0).equals(DEFAULT_INSTANCE_NAME); + return isOnlyDefaultInstance(keywordResults.getKeywordInstances(setName, keyword)); } @Override @@ -661,7 +664,6 @@ public class KeywordHits implements AutopsyVisitableItem { return s; } - } /** @@ -720,26 +722,21 @@ public class KeywordHits implements AutopsyVisitableItem { // The keys are different depending on what we are displaying. // regexp get another layer to show instances. // Exact/substring matches don't. - if ((instances.size() == 1) && (instances.get(0).equals(DEFAULT_INSTANCE_NAME))) { - for (Long id : keywordResults.getArtifactIds(setName, keyword, DEFAULT_INSTANCE_NAME)) { - RegExpInstanceKey key = new RegExpInstanceKey(id); - nodesMap.computeIfAbsent(key, k -> createNode(k)); - list.add(key); - } + if (isOnlyDefaultInstance(instances)) { + list.addAll(keywordResults.getArtifactIds(setName, keyword, DEFAULT_INSTANCE_NAME).stream() + .map(RegExpInstanceKey::new) + .collect(Collectors.toList())); } else { - for (String instance : instances) { - RegExpInstanceKey key = new RegExpInstanceKey(instance); - nodesMap.computeIfAbsent(key, k -> createNode(k)); - list.add(key); - } - + list.addAll(instances.stream() + .map(RegExpInstanceKey::new) + .collect(Collectors.toList())); } return true; } @Override protected Node createNodeForKey(RegExpInstanceKey key) { - return nodesMap.get(key); + return nodesMap.computeIfAbsent(key, this::createNode); } private DisplayableItemNode createNode(RegExpInstanceKey key) { @@ -895,16 +892,13 @@ public class KeywordHits implements AutopsyVisitableItem { @Override protected boolean createKeys(List list) { - for (Long id : keywordResults.getArtifactIds(setName, keyword, instance)) { - nodesMap.computeIfAbsent(id, i -> createBlackboardArtifactNode(i)); - list.add(id); - } + list.addAll(keywordResults.getArtifactIds(setName, keyword, instance)); return true; } @Override protected Node createNodeForKey(Long artifactId) { - return nodesMap.get(artifactId); + return nodesMap.computeIfAbsent(artifactId, KeywordHits.this::createBlackboardArtifactNode); } } } From 2216b78a7d2e6f5f66196dbc03d06887a9abad0c Mon Sep 17 00:00:00 2001 From: millmanorama Date: Thu, 20 Jul 2017 17:37:53 +0200 Subject: [PATCH 2/2] remove unused maps, inline method only used in one place --- .../org/sleuthkit/autopsy/datamodel/KeywordHits.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/KeywordHits.java b/Core/src/org/sleuthkit/autopsy/datamodel/KeywordHits.java index 477ca2fa7b..343074ddc9 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/KeywordHits.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/KeywordHits.java @@ -24,7 +24,6 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; @@ -708,7 +707,6 @@ public class KeywordHits implements AutopsyVisitableItem { private final String keyword; private final String setName; - private final Map nodesMap = new HashMap<>(); private RegExpInstancesFactory(String setName, String keyword) { super(); @@ -736,10 +734,6 @@ public class KeywordHits implements AutopsyVisitableItem { @Override protected Node createNodeForKey(RegExpInstanceKey key) { - return nodesMap.computeIfAbsent(key, this::createNode); - } - - private DisplayableItemNode createNode(RegExpInstanceKey key) { if (key.isRegExp()) { return new RegExpInstanceNode(setName, keyword, key.getRegExpKey()); } else { @@ -747,6 +741,7 @@ public class KeywordHits implements AutopsyVisitableItem { return createBlackboardArtifactNode(key.getIdKey()); } } + } /** @@ -881,7 +876,6 @@ public class KeywordHits implements AutopsyVisitableItem { private final String keyword; private final String setName; private final String instance; - private final Map nodesMap = new HashMap<>(); private HitsFactory(String setName, String keyword, String instance) { super(); @@ -898,7 +892,7 @@ public class KeywordHits implements AutopsyVisitableItem { @Override protected Node createNodeForKey(Long artifactId) { - return nodesMap.computeIfAbsent(artifactId, KeywordHits.this::createBlackboardArtifactNode); + return createBlackboardArtifactNode(artifactId); } } }