19 package org.sleuthkit.autopsy.communications;
 
   21 import java.util.Objects;
 
   22 import java.util.logging.Level;
 
   38 final class AccountDeviceInstanceKey {
 
   40     private static final Logger logger = Logger.getLogger(AccountDeviceInstanceKey.class.getName());
 
   42     private final AccountDeviceInstance accountDeviceInstance;
 
   43     private final CommunicationsFilter filter;
 
   44     private final long messageCount;
 
   45     private final String dataSourceName;
 
   47     AccountDeviceInstanceKey(AccountDeviceInstance accountDeviceInstance, CommunicationsFilter filter, 
long msgCount) {
 
   48         this.accountDeviceInstance = accountDeviceInstance;
 
   50         this.messageCount = msgCount;
 
   51         this.dataSourceName = getDataSourceName(accountDeviceInstance);
 
   54     AccountDeviceInstance getAccountDeviceInstance() {
 
   55         return accountDeviceInstance;
 
   58     CommunicationsFilter getCommunicationsFilter() {
 
   62     long getMessageCount() {
 
   66     String getDataSourceName() {
 
   67         return dataSourceName;
 
   71     public String toString() {
 
   72         return accountDeviceInstance.getAccount().getTypeSpecificID();
 
   76     public int hashCode() {
 
   78         hash = 37 * hash + Objects.hashCode(this.accountDeviceInstance);
 
   79         hash = 37 * hash + (int) (this.messageCount ^ (this.messageCount >>> 32));
 
   80         hash = 37 * hash + Objects.hashCode(this.dataSourceName);
 
   85     public boolean equals(Object obj) {
 
   92         if (getClass() != obj.getClass()) {
 
   95         final AccountDeviceInstanceKey other = (AccountDeviceInstanceKey) obj;
 
   96         if (this.getMessageCount() != other.getMessageCount()) {
 
   99         if (!Objects.equals(
this.getDataSourceName(), other.getDataSourceName())) {
 
  102         return Objects.equals(this.getAccountDeviceInstance(), other.getAccountDeviceInstance());
 
  105     private static String getDataSourceName(AccountDeviceInstance accountDeviceInstance) {
 
  107             SleuthkitCase db = Case.getCurrentCaseThrows().getSleuthkitCase();
 
  108             for (DataSource dataSource : db.getDataSources()) {
 
  109                 if (dataSource.getDeviceId().equals(accountDeviceInstance.getDeviceId())) {
 
  110                     return db.getContentById(dataSource.getId()).getName();
 
  113         } 
catch (NoCurrentCaseException | TskCoreException ex) {
 
  114             logger.log(Level.SEVERE, 
"Error getting datasource name, falling back on device ID.", ex);
 
  116         return accountDeviceInstance.getDeviceId();