19 package org.sleuthkit.autopsy.filequery;
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
24 import org.openide.util.NbBundle.Messages;
30 class FileGroup
implements Comparable<FileGroup> {
32 private final FileGroup.GroupSortingAlgorithm groupSortingType;
33 private final GroupKey groupKey;
34 private final List<ResultFile> files;
35 private final String displayName;
43 FileGroup(FileGroup.GroupSortingAlgorithm groupSortingType, GroupKey groupKey) {
44 this.groupSortingType = groupSortingType;
45 this.groupKey = groupKey;
46 files =
new ArrayList<>();
47 this.displayName = groupKey.getDisplayName();
55 void addFile(ResultFile file) {
56 if (files.contains(file)) {
57 ResultFile existingCopy = files.get(files.indexOf(file));
58 existingCopy.addDuplicate(file.getFirstInstance());
69 String getDisplayName() {
78 GroupKey getGroupKey() {
85 void sortFiles(FileSorter sorter) {
86 Collections.sort(files, sorter);
99 public int compareTo(FileGroup otherGroup) {
101 switch (groupSortingType) {
103 return compareGroupsBySize(
this, otherGroup);
106 return compareGroupsByGroupKey(
this, otherGroup);
118 private static int compareGroupsByGroupKey(FileGroup group1, FileGroup group2) {
119 return group1.getGroupKey().compareTo(group2.getGroupKey());
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());
136 return compareGroupsByGroupKey(group1, group2);
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()),
147 BY_GROUP_SIZE(Bundle.FileGroup_groupSortingAlgorithm_groupSize_text());
149 private final String displayName;
156 GroupSortingAlgorithm(String name) {
161 public String toString() {
172 List<ResultFile> getFiles() {
173 return Collections.unmodifiableList(files);