Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
CommonAttributeValue.java
Go to the documentation of this file.
1 /*
2  *
3  * Autopsy Forensic Browser
4  *
5  * Copyright 2018-2019 Basis Technology Corp.
6  * Contact: carrier <at> sleuthkit <dot> org
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 package org.sleuthkit.autopsy.commonpropertiessearch;
21 
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.Collections;
25 import java.util.HashMap;
26 import java.util.HashSet;
27 import java.util.List;
28 import java.util.Map;
29 import java.util.Set;
30 import java.util.stream.Collectors;
31 import org.sleuthkit.datamodel.AbstractFile;
32 
37 final public class CommonAttributeValue {
38 
39  private final String value;
40  private final List<AbstractCommonAttributeInstance> fileInstances;
41  private final Map<String, Integer> fileNames = new HashMap<>();
42 
43  CommonAttributeValue(String value) {
44  this.value = value;
45  this.fileInstances = new ArrayList<>();
46  }
47 
48  public String getValue() {
49  return this.value;
50  }
51 
57  String getTokenFileName() {
58  String tokenFileName = null;
59  int maxValue = 0;
60  for (String key : fileNames.keySet()){
61  if (fileNames.get(key) > maxValue){
62  maxValue = fileNames.get(key);
63  tokenFileName = key;
64  }
65  }
66  return tokenFileName;
67  }
68 
74  public String getCases() {
75  return this.fileInstances.stream().map(AbstractCommonAttributeInstance::getCaseName).collect(Collectors.joining(", "));
76  }
77 
83  public Set<String> getDataSources() {
84  Set<String> sources = new HashSet<>();
85  for (AbstractCommonAttributeInstance data : this.fileInstances) {
86  sources.add(data.getDataSource());
87  }
88  return sources;
89  }
90 
98  int getNumberOfDataSourcesInCurrentCase() {
99  Set<Long> dataSourceIds = new HashSet<>();
100  for (AbstractCommonAttributeInstance data : this.fileInstances) {
101  AbstractFile file = data.getAbstractFile();
102  if (file != null) {
103  dataSourceIds.add(file.getDataSourceObjectId());
104  }
105  }
106  return dataSourceIds.size();
107  }
108 
109  void addInstance(AbstractCommonAttributeInstance metadata) {
110  if (metadata.getAbstractFile() != null) {
111  Integer currentValue = fileNames.get(metadata.getAbstractFile().getName());
112  currentValue = currentValue == null ? 1 : currentValue+1;
113  fileNames.put(metadata.getAbstractFile().getName(), currentValue);
114  }
115  this.fileInstances.add(metadata);
116  }
117 
118  public Collection<AbstractCommonAttributeInstance> getInstances() {
119  return Collections.unmodifiableCollection(this.fileInstances);
120  }
121 
128  public int getInstanceCount() {
129  return this.fileInstances.size();
130  }
131 }
Collection< AbstractCommonAttributeInstance > getInstances()

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