Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
Group.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2019-2020 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.discovery.search;
20 
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
24 import org.openide.util.NbBundle.Messages;
25 
29 public class Group implements Comparable<Group> {
30 
33  private final List<Result> results;
34  private final String displayName;
35 
44  this.groupKey = groupKey;
45  results = new ArrayList<>();
46  this.displayName = groupKey.getDisplayName();
47  }
48 
54  void addResult(Result result) {
55  if (result.getType() != SearchData.Type.DOMAIN && results.contains(result)) {
56  //dedupe files and show instances
57  ResultFile existingCopy = (ResultFile) results.get(results.indexOf(result)); //get the copy of this which exists in the list
58  existingCopy.addDuplicate(((ResultFile) result).getFirstInstance());
59  } else {
60  //Domains and non files are not being deduped currently
61  results.add(result);
62  }
63  }
64 
70  public String getDisplayName() {
71  return displayName; // NON-NLS
72  }
73 
80  return groupKey;
81  }
82 
86  public void sortResults(ResultsSorter sorter) {
87  Collections.sort(results, sorter);
88  }
89 
99  @Override
100  public int compareTo(Group otherGroup) {
101 
102  switch (groupSortingType) {
103  case BY_GROUP_SIZE:
104  return compareGroupsBySize(this, otherGroup);
105  case BY_GROUP_NAME:
106  default:
107  return compareGroupsByGroupKey(this, otherGroup);
108  }
109  }
110 
119  private static int compareGroupsByGroupKey(Group group1, Group group2) {
120  return group1.getGroupKey().compareTo(group2.getGroupKey());
121  }
122 
132  private static int compareGroupsBySize(Group group1, Group group2) {
133  if (group1.getResults().size() != group2.getResults().size()) {
134  return -1 * Long.compare(group1.getResults().size(), group2.getResults().size()); // High to low
135  } else {
136  // If the groups have the same size, fall through to the BY_GROUP_NAME sorting
137  return compareGroupsByGroupKey(group1, group2);
138  }
139  }
140 
144  @Messages({"FileGroup.groupSortingAlgorithm.groupSize.text=Group Size",
145  "FileGroup.groupSortingAlgorithm.groupName.text=Group Name"})
146  public enum GroupSortingAlgorithm {
147  BY_GROUP_NAME(Bundle.FileGroup_groupSortingAlgorithm_groupName_text()), // Sort using the group key (for example, if grouping by size sort from largest to smallest value)
148  BY_GROUP_SIZE(Bundle.FileGroup_groupSortingAlgorithm_groupSize_text()); // Sort from largest to smallest group
149 
150  private final String displayName;
151 
157  GroupSortingAlgorithm(String name) {
158  displayName = name;
159  }
160 
161  @Override
162  public String toString() {
163  return displayName;
164  }
165 
166  }
167 
173  public List<Result> getResults() {
174  return Collections.unmodifiableList(results);
175  }
176 
177 }
final DiscoveryKeyUtils.GroupKey groupKey
Definition: Group.java:32
void sortResults(ResultsSorter sorter)
Definition: Group.java:86
Group(Group.GroupSortingAlgorithm groupSortingType, DiscoveryKeyUtils.GroupKey groupKey)
Definition: Group.java:42
static int compareGroupsBySize(Group group1, Group group2)
Definition: Group.java:132
final Group.GroupSortingAlgorithm groupSortingType
Definition: Group.java:31
static int compareGroupsByGroupKey(Group group1, Group group2)
Definition: Group.java:119
DiscoveryKeyUtils.GroupKey getGroupKey()
Definition: Group.java:79

Copyright © 2012-2022 Basis Technology. Generated on: Mon Sep 26 2022
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.