Autopsy  4.13.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
FileGroup.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2019 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.filequery;
20 
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
24 import org.openide.util.NbBundle.Messages;
26 
30 class FileGroup implements Comparable<FileGroup> {
31 
32  private final FileGroup.GroupSortingAlgorithm groupSortingType;
33  private final GroupKey groupKey;
34  private final List<ResultFile> files;
35  private final String displayName;
36 
43  FileGroup(FileGroup.GroupSortingAlgorithm groupSortingType, GroupKey groupKey) {
44  this.groupSortingType = groupSortingType;
45  this.groupKey = groupKey;
46  files = new ArrayList<>();
47  this.displayName = groupKey.getDisplayName();
48  }
49 
55  void addFile(ResultFile file) {
56  if (files.contains(file)) {
57  ResultFile existingCopy = files.get(files.indexOf(file)); //get the copy of this which exists in the list
58  existingCopy.addDuplicate(file.getFirstInstance());
59  } else {
60  files.add(file);
61  }
62  }
63 
69  String getDisplayName() {
70  return displayName; // NON-NLS
71  }
72 
78  GroupKey getGroupKey() {
79  return groupKey;
80  }
81 
85  void sortFiles(FileSorter sorter) {
86  Collections.sort(files, sorter);
87  }
88 
98  @Override
99  public int compareTo(FileGroup otherGroup) {
100 
101  switch (groupSortingType) {
102  case BY_GROUP_SIZE:
103  return compareGroupsBySize(this, otherGroup);
104  case BY_GROUP_NAME:
105  default:
106  return compareGroupsByGroupKey(this, otherGroup);
107  }
108  }
109 
118  private static int compareGroupsByGroupKey(FileGroup group1, FileGroup group2) {
119  return group1.getGroupKey().compareTo(group2.getGroupKey());
120  }
121 
131  private static int compareGroupsBySize(FileGroup group1, FileGroup group2) {
132  if (group1.getFiles().size() != group2.getFiles().size()) {
133  return -1 * Long.compare(group1.getFiles().size(), group2.getFiles().size()); // High to low
134  } else {
135  // If the groups have the same size, fall through to the BY_GROUP_NAME sorting
136  return compareGroupsByGroupKey(group1, group2);
137  }
138  }
139 
143  @Messages({"FileGroup.groupSortingAlgorithm.groupSize.text=Group Size",
144  "FileGroup.groupSortingAlgorithm.groupName.text=Group Name"})
145  enum GroupSortingAlgorithm {
146  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)
147  BY_GROUP_SIZE(Bundle.FileGroup_groupSortingAlgorithm_groupSize_text()); // Sort from largest to smallest group
148 
149  private final String displayName;
150 
156  GroupSortingAlgorithm(String name) {
157  displayName = name;
158  }
159 
160  @Override
161  public String toString() {
162  return displayName;
163  }
164 
165  }
166 
172  List<ResultFile> getFiles() {
173  return Collections.unmodifiableList(files);
174  }
175 
176 }

Copyright © 2012-2019 Basis Technology. Generated on: Tue Jan 7 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.