Autopsy  4.16.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DiscoveryKeyUtils.java
Go to the documentation of this file.
1 /*
2  * Autopsy
3  *
4  * Copyright 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.text.SimpleDateFormat;
22 import java.util.Collections;
23 import java.util.Date;
24 import java.util.List;
25 import java.util.Locale;
26 import java.util.Objects;
27 import java.util.concurrent.TimeUnit;
28 import java.util.logging.Level;
29 import org.openide.util.NbBundle;
32 import org.sleuthkit.datamodel.AbstractFile;
33 import org.sleuthkit.datamodel.Content;
34 import org.sleuthkit.datamodel.SleuthkitCase;
35 import org.sleuthkit.datamodel.TskCoreException;
36 
40 public class DiscoveryKeyUtils {
41 
42  private final static Logger logger = Logger.getLogger(DiscoveryKeyUtils.class.getName());
43 
47  static class SearchKey implements Comparable<SearchKey> {
48 
49  private final String keyString;
50  private final Group.GroupSortingAlgorithm groupSortingType;
51  private final DiscoveryAttributes.AttributeType groupAttributeType;
52  private final ResultsSorter.SortingMethod sortingMethod;
53  private final List<AbstractFilter> filters;
54  private final SleuthkitCase sleuthkitCase;
55  private final CentralRepository centralRepository;
56 
68  SearchKey(String userName, List<AbstractFilter> filters,
69  DiscoveryAttributes.AttributeType groupAttributeType,
70  Group.GroupSortingAlgorithm groupSortingType,
71  ResultsSorter.SortingMethod sortingMethod,
72  SleuthkitCase sleuthkitCase, CentralRepository centralRepository) {
73  this.groupAttributeType = groupAttributeType;
74  this.groupSortingType = groupSortingType;
75  this.sortingMethod = sortingMethod;
76  this.filters = filters;
77 
78  StringBuilder searchStringBuilder = new StringBuilder();
79  searchStringBuilder.append(userName);
80  for (AbstractFilter filter : filters) {
81  searchStringBuilder.append(filter.toString());
82  }
83  searchStringBuilder.append(groupAttributeType).append(groupSortingType).append(sortingMethod);
84  keyString = searchStringBuilder.toString();
85  this.sleuthkitCase = sleuthkitCase;
86  this.centralRepository = centralRepository;
87  }
88 
99  SearchKey(String userName, List<AbstractFilter> filters,
100  DiscoveryAttributes.AttributeType groupAttributeType,
101  Group.GroupSortingAlgorithm groupSortingType,
102  ResultsSorter.SortingMethod sortingMethod) {
103  this(userName, filters, groupAttributeType, groupSortingType,
104  sortingMethod, null, null);
105  }
106 
107  @Override
108  public int compareTo(SearchKey otherSearchKey) {
109  return getKeyString().compareTo(otherSearchKey.getKeyString());
110  }
111 
112  @Override
113  public boolean equals(Object otherKey) {
114  if (otherKey == this) {
115  return true;
116  }
117 
118  if (!(otherKey instanceof SearchKey)) {
119  return false;
120  }
121 
122  SearchKey otherSearchKey = (SearchKey) otherKey;
123  if (this.sleuthkitCase != otherSearchKey.getSleuthkitCase()
124  || this.centralRepository != otherSearchKey.getCentralRepository()) {
125  return false;
126  }
127 
128  return getKeyString().equals(otherSearchKey.getKeyString());
129  }
130 
131  @Override
132  public int hashCode() {
133  int hash = 5;
134  hash = 79 * hash + Objects.hashCode(getKeyString());
135  return hash;
136  }
137 
143  String getKeyString() {
144  return keyString;
145  }
146 
152  List<AbstractFilter> getFilters() {
153  return Collections.unmodifiableList(this.filters);
154  }
155 
161  Group.GroupSortingAlgorithm getGroupSortingType() {
162  return groupSortingType;
163  }
164 
170  DiscoveryAttributes.AttributeType getGroupAttributeType() {
171  return groupAttributeType;
172  }
173 
179  ResultsSorter.SortingMethod getFileSortingMethod() {
180  return sortingMethod;
181  }
182 
188  SleuthkitCase getSleuthkitCase() {
189  return this.sleuthkitCase;
190  }
191 
197  CentralRepository getCentralRepository() {
198  return this.centralRepository;
199  }
200  }
201 
205  public abstract static class GroupKey implements Comparable<GroupKey> {
206 
213  abstract String getDisplayName();
214 
222  @Override
223  abstract public boolean equals(Object otherKey);
224 
230  @Override
231  abstract public int hashCode();
232 
242  int compareClassNames(GroupKey otherGroupKey) {
243  return this.getClass().getName().compareTo(otherGroupKey.getClass().getName());
244  }
245 
246  @Override
247  public String toString() {
248  return getDisplayName();
249  }
250  }
251 
255  static class FileSizeGroupKey extends GroupKey {
256 
257  private final SearchData.FileSize fileSize;
258 
264  FileSizeGroupKey(Result file) {
265  ResultFile resultFile = (ResultFile) file;
266  if (resultFile.getFileType() == SearchData.Type.VIDEO) {
267  fileSize = SearchData.FileSize.fromVideoSize(resultFile.getFirstInstance().getSize());
268  } else {
269  fileSize = SearchData.FileSize.fromImageSize(resultFile.getFirstInstance().getSize());
270  }
271  }
272 
273  @Override
274  String getDisplayName() {
275  return getFileSize().toString();
276  }
277 
278  @Override
279  public int compareTo(GroupKey otherGroupKey) {
280  if (otherGroupKey instanceof FileSizeGroupKey) {
281  FileSizeGroupKey otherFileSizeGroupKey = (FileSizeGroupKey) otherGroupKey;
282  return Integer.compare(getFileSize().getRanking(), otherFileSizeGroupKey.getFileSize().getRanking());
283  } else {
284  return compareClassNames(otherGroupKey);
285  }
286  }
287 
288  @Override
289  public boolean equals(Object otherKey) {
290  if (otherKey == this) {
291  return true;
292  }
293 
294  if (!(otherKey instanceof FileSizeGroupKey)) {
295  return false;
296  }
297 
298  FileSizeGroupKey otherFileSizeGroupKey = (FileSizeGroupKey) otherKey;
299  return getFileSize().equals(otherFileSizeGroupKey.getFileSize());
300  }
301 
302  @Override
303  public int hashCode() {
304  return Objects.hash(getFileSize().getRanking());
305  }
306 
312  SearchData.FileSize getFileSize() {
313  return fileSize;
314  }
315  }
316 
320  static class FileTypeGroupKey extends GroupKey {
321 
322  private final SearchData.Type fileType;
323 
329  FileTypeGroupKey(Result file) {
330  fileType = ((ResultFile) file).getFileType();
331  }
332 
333  @Override
334  String getDisplayName() {
335  return getFileType().toString();
336  }
337 
338  @Override
339  public int compareTo(GroupKey otherGroupKey) {
340  if (otherGroupKey instanceof FileTypeGroupKey) {
341  FileTypeGroupKey otherFileTypeGroupKey = (FileTypeGroupKey) otherGroupKey;
342  return Integer.compare(getFileType().getRanking(), otherFileTypeGroupKey.getFileType().getRanking());
343  } else {
344  return compareClassNames(otherGroupKey);
345  }
346  }
347 
348  @Override
349  public boolean equals(Object otherKey) {
350  if (otherKey == this) {
351  return true;
352  }
353 
354  if (!(otherKey instanceof FileTypeGroupKey)) {
355  return false;
356  }
357 
358  FileTypeGroupKey otherFileTypeGroupKey = (FileTypeGroupKey) otherKey;
359  return getFileType().equals(otherFileTypeGroupKey.getFileType());
360  }
361 
362  @Override
363  public int hashCode() {
364  return Objects.hash(getFileType().getRanking());
365  }
366 
372  SearchData.Type getFileType() {
373  return fileType;
374  }
375  }
376 
380  static class KeywordListGroupKey extends GroupKey {
381 
382  private final List<String> keywordListNames;
383  private final String keywordListNamesString;
384 
390  @NbBundle.Messages({
391  "DiscoveryKeyUtils.KeywordListGroupKey.noKeywords=None"})
392  KeywordListGroupKey(ResultFile file) {
393  keywordListNames = file.getKeywordListNames();
394  if (keywordListNames.isEmpty()) {
395  keywordListNamesString = Bundle.DiscoveryKeyUtils_KeywordListGroupKey_noKeywords();
396  } else {
397  keywordListNamesString = String.join(",", keywordListNames); // NON-NLS
398  }
399  }
400 
401  @Override
402  String getDisplayName() {
403  return getKeywordListNamesString();
404  }
405 
406  @Override
407  public int compareTo(GroupKey otherGroupKey) {
408  if (otherGroupKey instanceof KeywordListGroupKey) {
409  KeywordListGroupKey otherKeywordListNamesGroupKey = (KeywordListGroupKey) otherGroupKey;
410 
411  // Put the empty list at the end
412  if (getKeywordListNames().isEmpty()) {
413  if (otherKeywordListNamesGroupKey.getKeywordListNames().isEmpty()) {
414  return 0;
415  } else {
416  return 1;
417  }
418  } else if (otherKeywordListNamesGroupKey.getKeywordListNames().isEmpty()) {
419  return -1;
420  }
421 
422  return getKeywordListNamesString().compareTo(otherKeywordListNamesGroupKey.getKeywordListNamesString());
423  } else {
424  return compareClassNames(otherGroupKey);
425  }
426  }
427 
428  @Override
429  public boolean equals(Object otherKey) {
430  if (otherKey == this) {
431  return true;
432  }
433 
434  if (!(otherKey instanceof KeywordListGroupKey)) {
435  return false;
436  }
437 
438  KeywordListGroupKey otherKeywordListGroupKey = (KeywordListGroupKey) otherKey;
439  return getKeywordListNamesString().equals(otherKeywordListGroupKey.getKeywordListNamesString());
440  }
441 
442  @Override
443  public int hashCode() {
444  return Objects.hash(getKeywordListNamesString());
445  }
446 
452  List<String> getKeywordListNames() {
453  return Collections.unmodifiableList(keywordListNames);
454  }
455 
463  String getKeywordListNamesString() {
464  return keywordListNamesString;
465  }
466  }
467 
471  static class FileTagGroupKey extends GroupKey {
472 
473  private final List<String> tagNames;
474  private final String tagNamesString;
475 
481  @NbBundle.Messages({
482  "DiscoveryKeyUtils.FileTagGroupKey.noSets=None"})
483  FileTagGroupKey(ResultFile file) {
484  tagNames = file.getTagNames();
485 
486  if (tagNames.isEmpty()) {
487  tagNamesString = Bundle.DiscoveryKeyUtils_FileTagGroupKey_noSets();
488  } else {
489  tagNamesString = String.join(",", tagNames); // NON-NLS
490  }
491  }
492 
493  @Override
494  String getDisplayName() {
495  return getTagNamesString();
496  }
497 
498  @Override
499  public int compareTo(GroupKey otherGroupKey) {
500  if (otherGroupKey instanceof FileTagGroupKey) {
501  FileTagGroupKey otherFileTagGroupKey = (FileTagGroupKey) otherGroupKey;
502 
503  // Put the empty list at the end
504  if (getTagNames().isEmpty()) {
505  if (otherFileTagGroupKey.getTagNames().isEmpty()) {
506  return 0;
507  } else {
508  return 1;
509  }
510  } else if (otherFileTagGroupKey.getTagNames().isEmpty()) {
511  return -1;
512  }
513 
514  return getTagNamesString().compareTo(otherFileTagGroupKey.getTagNamesString());
515  } else {
516  return compareClassNames(otherGroupKey);
517  }
518  }
519 
520  @Override
521  public boolean equals(Object otherKey) {
522  if (otherKey == this) {
523  return true;
524  }
525  if (!(otherKey instanceof FileTagGroupKey)) {
526  return false;
527  }
528  FileTagGroupKey otherFileTagGroupKey = (FileTagGroupKey) otherKey;
529  return getTagNamesString().equals(otherFileTagGroupKey.getTagNamesString());
530  }
531 
532  @Override
533  public int hashCode() {
534  return Objects.hash(getTagNamesString());
535  }
536 
542  List<String> getTagNames() {
543  return Collections.unmodifiableList(tagNames);
544  }
545 
553  String getTagNamesString() {
554  return tagNamesString;
555  }
556  }
557 
561  static class ParentPathGroupKey extends GroupKey {
562 
563  private String parentPath;
564  private Long parentID;
565 
571  ParentPathGroupKey(ResultFile file) {
572  Content parent;
573  try {
574  parent = file.getFirstInstance().getParent();
575  } catch (TskCoreException ignored) {
576  parent = null;
577  }
578  //Find the directory this file is in if it is an embedded file
579  while (parent != null && parent instanceof AbstractFile && ((AbstractFile) parent).isFile()) {
580  try {
581  parent = parent.getParent();
582  } catch (TskCoreException ignored) {
583  parent = null;
584  }
585  }
586  setParentPathAndID(parent, file);
587  }
588 
595  private void setParentPathAndID(Content parent, ResultFile file) {
596  if (parent != null) {
597  try {
598  parentPath = parent.getUniquePath();
599  parentID = parent.getId();
600  } catch (TskCoreException ignored) {
601  //catch block left blank purposefully next if statement will handle case when exception takes place as well as when parent is null
602  }
603 
604  }
605  if (parentPath == null) {
606  if (file.getFirstInstance().getParentPath() != null) {
607  parentPath = file.getFirstInstance().getParentPath();
608  } else {
609  parentPath = ""; // NON-NLS
610  }
611  parentID = -1L;
612  }
613  }
614 
615  @Override
616  String getDisplayName() {
617  return getParentPath();
618  }
619 
620  @Override
621  public int compareTo(GroupKey otherGroupKey) {
622  if (otherGroupKey instanceof ParentPathGroupKey) {
623  ParentPathGroupKey otherParentPathGroupKey = (ParentPathGroupKey) otherGroupKey;
624  int comparisonResult = getParentPath().compareTo(otherParentPathGroupKey.getParentPath());
625  if (comparisonResult == 0) {
626  comparisonResult = getParentID().compareTo(otherParentPathGroupKey.getParentID());
627  }
628  return comparisonResult;
629  } else {
630  return compareClassNames(otherGroupKey);
631  }
632  }
633 
634  @Override
635  public boolean equals(Object otherKey) {
636  if (otherKey == this) {
637  return true;
638  }
639 
640  if (!(otherKey instanceof ParentPathGroupKey)) {
641  return false;
642  }
643 
644  ParentPathGroupKey otherParentPathGroupKey = (ParentPathGroupKey) otherKey;
645  return getParentPath().equals(otherParentPathGroupKey.getParentPath()) && getParentID().equals(otherParentPathGroupKey.getParentID());
646  }
647 
648  @Override
649  public int hashCode() {
650  int hashCode = 11;
651  hashCode = 61 * hashCode + Objects.hash(getParentPath());
652  hashCode = 61 * hashCode + Objects.hash(getParentID());
653  return hashCode;
654  }
655 
661  String getParentPath() {
662  return parentPath;
663  }
664 
670  Long getParentID() {
671  return parentID;
672  }
673  }
674 
678  static class DataSourceGroupKey extends GroupKey {
679 
680  private final long dataSourceID;
681  private String displayName;
682 
688  @NbBundle.Messages({
689  "# {0} - Data source name",
690  "# {1} - Data source ID",
691  "DiscoveryKeyUtils.DataSourceGroupKey.datasourceAndID={0}(ID: {1})",
692  "# {0} - Data source ID",
693  "DiscoveryKeyUtils.DataSourceGroupKey.idOnly=Data source (ID: {0})"})
694  DataSourceGroupKey(Result result) {
695  //get the id first so that it can be used when logging if necessary
696  dataSourceID = result.getDataSourceObjectId();
697  try {
698  // The data source should be cached so this won't actually be a database query.
699  Content ds = result.getDataSource();
700  displayName = Bundle.DiscoveryKeyUtils_DataSourceGroupKey_datasourceAndID(ds.getName(), ds.getId());
701  } catch (TskCoreException ex) {
702  logger.log(Level.WARNING, "Error looking up data source with ID " + dataSourceID, ex); // NON-NLS
703  displayName = Bundle.DiscoveryKeyUtils_DataSourceGroupKey_idOnly(dataSourceID);
704  }
705  }
706 
707  @Override
708  String getDisplayName() {
709  return displayName;
710  }
711 
712  @Override
713  public int compareTo(GroupKey otherGroupKey) {
714  if (otherGroupKey instanceof DataSourceGroupKey) {
715  DataSourceGroupKey otherDataSourceGroupKey = (DataSourceGroupKey) otherGroupKey;
716  return Long.compare(getDataSourceID(), otherDataSourceGroupKey.getDataSourceID());
717  } else {
718  return compareClassNames(otherGroupKey);
719  }
720  }
721 
722  @Override
723  public boolean equals(Object otherKey) {
724  if (otherKey == this) {
725  return true;
726  }
727 
728  if (!(otherKey instanceof DataSourceGroupKey)) {
729  return false;
730  }
731 
732  DataSourceGroupKey otherDataSourceGroupKey = (DataSourceGroupKey) otherKey;
733  return getDataSourceID() == otherDataSourceGroupKey.getDataSourceID();
734  }
735 
736  @Override
737  public int hashCode() {
738  return Objects.hash(getDataSourceID());
739  }
740 
746  long getDataSourceID() {
747  return dataSourceID;
748  }
749  }
750 
755  static class NoGroupingGroupKey extends GroupKey {
756 
760  NoGroupingGroupKey() {
761  // Nothing to save - all files will get the same GroupKey
762  }
763 
764  @NbBundle.Messages({
765  "DiscoveryKeyUtils.NoGroupingGroupKey.allFiles=All Files"})
766  @Override
767  String getDisplayName() {
768  return Bundle.DiscoveryKeyUtils_NoGroupingGroupKey_allFiles();
769  }
770 
771  @Override
772  public int compareTo(GroupKey otherGroupKey) {
773  // As long as the other key is the same type, they are equal
774  if (otherGroupKey instanceof NoGroupingGroupKey) {
775  return 0;
776  } else {
777  return compareClassNames(otherGroupKey);
778  }
779  }
780 
781  @Override
782  public boolean equals(Object otherKey) {
783  if (otherKey == this) {
784  return true;
785  }
786  // As long as the other key is the same type, they are equal
787  return otherKey instanceof NoGroupingGroupKey;
788  }
789 
790  @Override
791  public int hashCode() {
792  return 0;
793  }
794  }
795 
799  static class FrequencyGroupKey extends GroupKey {
800 
801  private final SearchData.Frequency frequency;
802 
808  FrequencyGroupKey(Result result) {
809  frequency = result.getFrequency();
810  }
811 
812  @Override
813  String getDisplayName() {
814  return getFrequency().toString();
815  }
816 
817  @Override
818  public int compareTo(GroupKey otherGroupKey) {
819  if (otherGroupKey instanceof FrequencyGroupKey) {
820  FrequencyGroupKey otherFrequencyGroupKey = (FrequencyGroupKey) otherGroupKey;
821  return Integer.compare(getFrequency().getRanking(), otherFrequencyGroupKey.getFrequency().getRanking());
822  } else {
823  return compareClassNames(otherGroupKey);
824  }
825  }
826 
827  @Override
828  public boolean equals(Object otherKey) {
829  if (otherKey == this) {
830  return true;
831  }
832 
833  if (!(otherKey instanceof FrequencyGroupKey)) {
834  return false;
835  }
836 
837  FrequencyGroupKey otherFrequencyGroupKey = (FrequencyGroupKey) otherKey;
838  return getFrequency().equals(otherFrequencyGroupKey.getFrequency());
839  }
840 
841  @Override
842  public int hashCode() {
843  return Objects.hash(getFrequency().getRanking());
844  }
845 
851  SearchData.Frequency getFrequency() {
852  return frequency;
853  }
854  }
855 
859  static class HashHitsGroupKey extends GroupKey {
860 
861  private final List<String> hashSetNames;
862  private final String hashSetNamesString;
863 
869  @NbBundle.Messages({
870  "DiscoveryKeyUtils.HashHitsGroupKey.noHashHits=None"})
871  HashHitsGroupKey(ResultFile file) {
872  hashSetNames = file.getHashSetNames();
873 
874  if (hashSetNames.isEmpty()) {
875  hashSetNamesString = Bundle.DiscoveryKeyUtils_HashHitsGroupKey_noHashHits();
876  } else {
877  hashSetNamesString = String.join(",", hashSetNames); // NON-NLS
878  }
879  }
880 
881  @Override
882  String getDisplayName() {
883  return getHashSetNamesString();
884  }
885 
886  @Override
887  public int compareTo(GroupKey otherGroupKey) {
888  if (otherGroupKey instanceof HashHitsGroupKey) {
889  HashHitsGroupKey otherHashHitsGroupKey = (HashHitsGroupKey) otherGroupKey;
890 
891  // Put the empty list at the end
892  if (getHashSetNames().isEmpty()) {
893  if (otherHashHitsGroupKey.getHashSetNames().isEmpty()) {
894  return 0;
895  } else {
896  return 1;
897  }
898  } else if (otherHashHitsGroupKey.getHashSetNames().isEmpty()) {
899  return -1;
900  }
901 
902  return getHashSetNamesString().compareTo(otherHashHitsGroupKey.getHashSetNamesString());
903  } else {
904  return compareClassNames(otherGroupKey);
905  }
906  }
907 
908  @Override
909  public boolean equals(Object otherKey) {
910  if (otherKey == this) {
911  return true;
912  }
913 
914  if (!(otherKey instanceof HashHitsGroupKey)) {
915  return false;
916  }
917 
918  HashHitsGroupKey otherHashHitsGroupKey = (HashHitsGroupKey) otherKey;
919  return getHashSetNamesString().equals(otherHashHitsGroupKey.getHashSetNamesString());
920  }
921 
922  @Override
923  public int hashCode() {
924  return Objects.hash(getHashSetNamesString());
925  }
926 
932  List<String> getHashSetNames() {
933  return Collections.unmodifiableList(hashSetNames);
934  }
935 
941  String getHashSetNamesString() {
942  return hashSetNamesString;
943  }
944  }
945 
949  static class InterestingItemGroupKey extends GroupKey {
950 
951  private final List<String> interestingItemSetNames;
952  private final String interestingItemSetNamesString;
953 
959  @NbBundle.Messages({
960  "DiscoveryKeyUtils.InterestingItemGroupKey.noSets=None"})
961  InterestingItemGroupKey(ResultFile file) {
962  interestingItemSetNames = file.getInterestingSetNames();
963 
964  if (interestingItemSetNames.isEmpty()) {
965  interestingItemSetNamesString = Bundle.DiscoveryKeyUtils_InterestingItemGroupKey_noSets();
966  } else {
967  interestingItemSetNamesString = String.join(",", interestingItemSetNames); // NON-NLS
968  }
969  }
970 
971  @Override
972  String getDisplayName() {
973  return getInterestingItemSetNamesString();
974  }
975 
976  @Override
977  public int compareTo(GroupKey otherGroupKey) {
978  if (otherGroupKey instanceof InterestingItemGroupKey) {
979  InterestingItemGroupKey otherInterestingItemGroupKey = (InterestingItemGroupKey) otherGroupKey;
980 
981  // Put the empty list at the end
982  if (this.getInterestingItemSetNames().isEmpty()) {
983  if (otherInterestingItemGroupKey.getInterestingItemSetNames().isEmpty()) {
984  return 0;
985  } else {
986  return 1;
987  }
988  } else if (otherInterestingItemGroupKey.getInterestingItemSetNames().isEmpty()) {
989  return -1;
990  }
991 
992  return getInterestingItemSetNamesString().compareTo(otherInterestingItemGroupKey.getInterestingItemSetNamesString());
993  } else {
994  return compareClassNames(otherGroupKey);
995  }
996  }
997 
998  @Override
999  public boolean equals(Object otherKey) {
1000  if (otherKey == this) {
1001  return true;
1002  }
1003 
1004  if (!(otherKey instanceof InterestingItemGroupKey)) {
1005  return false;
1006  }
1007 
1008  InterestingItemGroupKey otherInterestingItemGroupKey = (InterestingItemGroupKey) otherKey;
1009  return getInterestingItemSetNamesString().equals(otherInterestingItemGroupKey.getInterestingItemSetNamesString());
1010  }
1011 
1012  @Override
1013  public int hashCode() {
1014  return Objects.hash(getInterestingItemSetNamesString());
1015  }
1016 
1022  List<String> getInterestingItemSetNames() {
1023  return Collections.unmodifiableList(interestingItemSetNames);
1024  }
1025 
1033  String getInterestingItemSetNamesString() {
1034  return interestingItemSetNamesString;
1035  }
1036  }
1037 
1041  static class MostRecentActivityDateGroupKey extends GroupKey {
1042 
1043  private final Long epochDate;
1044  private final String dateNameString;
1045 
1051  @NbBundle.Messages({
1052  "DiscoveryKeyUtils.MostRecentActivityDateGroupKey.noDate=No Date Available"})
1053  MostRecentActivityDateGroupKey(Result result) {
1054  if (result instanceof ResultDomain) {
1055  epochDate = ((ResultDomain) result).getActivityEnd();
1056  dateNameString = new SimpleDateFormat("yyyy/MM/dd", Locale.getDefault()).format(new Date(TimeUnit.SECONDS.toMillis(epochDate)));
1057  } else {
1058  epochDate = Long.MAX_VALUE;
1059  dateNameString = Bundle.DiscoveryKeyUtils_MostRecentActivityDateGroupKey_noDate();
1060  }
1061  }
1062 
1063  @Override
1064  String getDisplayName() {
1065  return getDateNameString();
1066  }
1067 
1068  @Override
1069  public boolean equals(Object otherKey) {
1070  if (otherKey == this) {
1071  return true;
1072  }
1073 
1074  if (!(otherKey instanceof MostRecentActivityDateGroupKey)) {
1075  return false;
1076  }
1077 
1078  MostRecentActivityDateGroupKey dateGroupKey = (MostRecentActivityDateGroupKey) otherKey;
1079  return getDateNameString().equals(dateGroupKey.getDateNameString());
1080  }
1081 
1082  @Override
1083  public int hashCode() {
1084  return Objects.hash(getDateNameString());
1085  }
1086 
1087  @Override
1088  public int compareTo(GroupKey otherGroupKey) {
1089  if (otherGroupKey instanceof MostRecentActivityDateGroupKey) {
1090  MostRecentActivityDateGroupKey otherDateGroupKey = (MostRecentActivityDateGroupKey) otherGroupKey;
1091 
1092  // Put the empty list at the end
1093  if (this.getEpochDate().equals(Long.MAX_VALUE)) {
1094  if (otherDateGroupKey.getEpochDate().equals(Long.MAX_VALUE)) {
1095  return 0;
1096  } else {
1097  return 1;
1098  }
1099  } else if (otherDateGroupKey.getEpochDate().equals(Long.MAX_VALUE)) {
1100  return -1;
1101  }
1102 
1103  return getDateNameString().compareTo(otherDateGroupKey.getDateNameString());
1104  } else {
1105  return compareClassNames(otherGroupKey);
1106  }
1107  }
1108 
1114  Long getEpochDate() {
1115  return epochDate;
1116  }
1117 
1123  String getDateNameString() {
1124  return dateNameString;
1125  }
1126  }
1127 
1131  static class FirstActivityDateGroupKey extends GroupKey {
1132 
1133  private final Long epochDate;
1134  private final String dateNameString;
1135 
1141  @NbBundle.Messages({
1142  "DiscoveryKeyUtils.FirstActivityDateGroupKey.noDate=No Date Available"})
1143  FirstActivityDateGroupKey(Result result) {
1144  if (result instanceof ResultDomain) {
1145  epochDate = ((ResultDomain) result).getActivityStart();
1146  dateNameString = new SimpleDateFormat("yyyy/MM/dd", Locale.getDefault()).format(new Date(TimeUnit.SECONDS.toMillis(epochDate)));
1147  } else {
1148  epochDate = Long.MAX_VALUE;
1149  dateNameString = Bundle.DiscoveryKeyUtils_FirstActivityDateGroupKey_noDate();
1150  }
1151  }
1152 
1153  @Override
1154  String getDisplayName() {
1155  return getDateNameString();
1156  }
1157 
1158  @Override
1159  public boolean equals(Object otherKey) {
1160  if (otherKey == this) {
1161  return true;
1162  }
1163 
1164  if (!(otherKey instanceof FirstActivityDateGroupKey)) {
1165  return false;
1166  }
1167 
1168  FirstActivityDateGroupKey dateGroupKey = (FirstActivityDateGroupKey) otherKey;
1169  return getDateNameString().equals(dateGroupKey.getDateNameString());
1170  }
1171 
1172  @Override
1173  public int hashCode() {
1174  return Objects.hash(getDateNameString());
1175  }
1176 
1177  @Override
1178  public int compareTo(GroupKey otherGroupKey) {
1179  if (otherGroupKey instanceof FirstActivityDateGroupKey) {
1180  FirstActivityDateGroupKey otherDateGroupKey = (FirstActivityDateGroupKey) otherGroupKey;
1181 
1182  // Put the empty list at the end
1183  if (this.getEpochDate().equals(Long.MAX_VALUE)) {
1184  if (otherDateGroupKey.getEpochDate().equals(Long.MAX_VALUE)) {
1185  return 0;
1186  } else {
1187  return 1;
1188  }
1189  } else if (otherDateGroupKey.getEpochDate().equals(Long.MAX_VALUE)) {
1190  return -1;
1191  }
1192 
1193  return getDateNameString().compareTo(otherDateGroupKey.getDateNameString());
1194  } else {
1195  return compareClassNames(otherGroupKey);
1196  }
1197  }
1198 
1204  Long getEpochDate() {
1205  return epochDate;
1206  }
1207 
1213  String getDateNameString() {
1214  return dateNameString;
1215  }
1216  }
1217 
1221  static class NumberOfVisitsGroupKey extends GroupKey {
1222 
1223  private final String displayName;
1224  private final Long visits;
1225 
1231  @NbBundle.Messages({
1232  "# {0} - totalVisits",
1233  "DiscoveryKeyUtils.NumberOfVisitsGroupKey.displayName={0} visits",
1234  "DiscoveryKeyUtils.NumberOfVisitsGroupKey.noVisits=No visits"})
1235  NumberOfVisitsGroupKey(Result result) {
1236  if (result instanceof ResultDomain) {
1237  Long totalVisits = ((ResultDomain) result).getTotalVisits();
1238  if (totalVisits == null) {
1239  totalVisits = 0L;
1240  }
1241  visits = totalVisits;
1242  displayName = Bundle.DiscoveryKeyUtils_NumberOfVisitsGroupKey_displayName(Long.toString(visits));
1243  } else {
1244  displayName = Bundle.DiscoveryKeyUtils_NumberOfVisitsGroupKey_noVisits();
1245  visits = -1L;
1246  }
1247  }
1248 
1249  @Override
1250  String getDisplayName() {
1251  return displayName;
1252  }
1253 
1254  @Override
1255  public int hashCode() {
1256  return Objects.hash(displayName);
1257  }
1258 
1264  Long getVisits() {
1265  return visits;
1266  }
1267 
1268  @Override
1269  public boolean equals(Object otherKey) {
1270  if (otherKey == this) {
1271  return true;
1272  }
1273 
1274  if (!(otherKey instanceof NumberOfVisitsGroupKey)) {
1275  return false;
1276  }
1277 
1278  NumberOfVisitsGroupKey visitsKey = (NumberOfVisitsGroupKey) otherKey;
1279  return visits.equals(visitsKey.getVisits());
1280  }
1281 
1282  @Override
1283  public int compareTo(GroupKey otherGroupKey) {
1284  if (otherGroupKey instanceof NumberOfVisitsGroupKey) {
1285  NumberOfVisitsGroupKey visitsKey = (NumberOfVisitsGroupKey) otherGroupKey;
1286  return Long.compare(getVisits(), visitsKey.getVisits());
1287  } else {
1288  return compareClassNames(otherGroupKey);
1289  }
1290  }
1291  }
1292 
1296  static class ObjectDetectedGroupKey extends GroupKey {
1297 
1298  private final List<String> objectDetectedNames;
1299  private final String objectDetectedNamesString;
1300 
1306  @NbBundle.Messages({
1307  "DiscoveryKeyUtils.ObjectDetectedGroupKey.noSets=None"})
1308  ObjectDetectedGroupKey(ResultFile file) {
1309  objectDetectedNames = file.getObjectDetectedNames();
1310  if (objectDetectedNames.isEmpty()) {
1311  objectDetectedNamesString = Bundle.DiscoveryKeyUtils_ObjectDetectedGroupKey_noSets();
1312  } else {
1313  objectDetectedNamesString = String.join(",", objectDetectedNames); // NON-NLS
1314  }
1315  }
1316 
1317  @Override
1318  String getDisplayName() {
1319  return getObjectDetectedNamesString();
1320  }
1321 
1322  @Override
1323  public int compareTo(GroupKey otherGroupKey) {
1324  if (otherGroupKey instanceof ObjectDetectedGroupKey) {
1325  ObjectDetectedGroupKey otherObjectDetectedGroupKey = (ObjectDetectedGroupKey) otherGroupKey;
1326 
1327  // Put the empty list at the end
1328  if (this.getObjectDetectedNames().isEmpty()) {
1329  if (otherObjectDetectedGroupKey.getObjectDetectedNames().isEmpty()) {
1330  return 0;
1331  } else {
1332  return 1;
1333  }
1334  } else if (otherObjectDetectedGroupKey.getObjectDetectedNames().isEmpty()) {
1335  return -1;
1336  }
1337 
1338  return getObjectDetectedNamesString().compareTo(otherObjectDetectedGroupKey.getObjectDetectedNamesString());
1339  } else {
1340  return compareClassNames(otherGroupKey);
1341  }
1342  }
1343 
1344  @Override
1345  public boolean equals(Object otherKey) {
1346  if (otherKey == this) {
1347  return true;
1348  }
1349 
1350  if (!(otherKey instanceof ObjectDetectedGroupKey)) {
1351  return false;
1352  }
1353 
1354  ObjectDetectedGroupKey otherObjectDetectedGroupKey = (ObjectDetectedGroupKey) otherKey;
1355  return getObjectDetectedNamesString().equals(otherObjectDetectedGroupKey.getObjectDetectedNamesString());
1356  }
1357 
1358  @Override
1359  public int hashCode() {
1360  return Objects.hash(getObjectDetectedNamesString());
1361  }
1362 
1368  List<String> getObjectDetectedNames() {
1369  return Collections.unmodifiableList(objectDetectedNames);
1370  }
1371 
1379  String getObjectDetectedNamesString() {
1380  return objectDetectedNamesString;
1381  }
1382  }
1383 
1387  private DiscoveryKeyUtils() {
1388  //private constructor in a utility class intentionally left blank
1389  }
1390 }
FileSize(int ranking, long minB, long maxB, String displayName, String displaySize)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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