19 package org.sleuthkit.autopsy.communications.relationships;
21 import java.util.Comparator;
22 import java.util.logging.Level;
33 class BlackboardArtifactDateComparator
implements Comparator<BlackboardArtifact> {
34 static final int ACCENDING = 1;
35 static final int DECENDING = -1;
37 private static final Logger logger = Logger.getLogger(BlackboardArtifactDateComparator.class.getName());
39 private final int direction;
41 BlackboardArtifactDateComparator(
int direction) {
42 this.direction = direction;
46 public int compare(BlackboardArtifact bba1, BlackboardArtifact bba2) {
48 BlackboardAttribute attribute1 = getTimeAttributeForArtifact(bba1);
49 BlackboardAttribute attribute2 = getTimeAttributeForArtifact(bba2);
53 long dateTime1 = Long.MAX_VALUE;
54 long dateTime2 = Long.MAX_VALUE;
56 if (attribute1 != null) {
57 dateTime1 = attribute1.getValueLong();
60 if (attribute2 != null) {
61 dateTime2 = attribute2.getValueLong();
64 return Long.compare(dateTime1, dateTime2) * direction;
67 private BlackboardAttribute getTimeAttributeForArtifact(BlackboardArtifact artifact) {
68 if(artifact == null) {
72 BlackboardAttribute attribute = null;
74 BlackboardArtifact.ARTIFACT_TYPE fromID = BlackboardArtifact.ARTIFACT_TYPE.fromID(artifact.getArtifactTypeID());
79 attribute = artifact.getAttribute(
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_SENT));
82 attribute = artifact.getAttribute(
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME));
85 attribute = artifact.getAttribute(
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_START));
91 }
catch (TskCoreException ex) {
92 logger.log(Level.WARNING, String.format(
"Unable to compare attributes for artifact %d", artifact.getArtifactID()), ex);