mirror of
https://github.com/mitb-archive/filebot
synced 2024-11-10 11:25:04 -05:00
* prefer using creationDate over lastModified
This commit is contained in:
parent
93cff16ea7
commit
a7d37d43e6
@ -5,6 +5,8 @@ package net.sourceforge.filebot.similarity;
|
|||||||
import static java.lang.Math.*;
|
import static java.lang.Math.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
|
||||||
|
|
||||||
public class TimeStampMetric implements SimilarityMetric {
|
public class TimeStampMetric implements SimilarityMetric {
|
||||||
@ -26,7 +28,18 @@ public class TimeStampMetric implements SimilarityMetric {
|
|||||||
|
|
||||||
public long getTimeStamp(Object obj) {
|
public long getTimeStamp(Object obj) {
|
||||||
if (obj instanceof File) {
|
if (obj instanceof File) {
|
||||||
return ((File) obj).lastModified();
|
try {
|
||||||
|
BasicFileAttributes attr = Files.readAttributes(((File) obj).toPath(), BasicFileAttributes.class);
|
||||||
|
long creationTime = attr.creationTime().toMillis();
|
||||||
|
if (creationTime > 0) {
|
||||||
|
return creationTime;
|
||||||
|
} else {
|
||||||
|
return attr.lastModifiedTime().toMillis();
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
// ignore Java 6 issues
|
||||||
|
return ((File) obj).lastModified();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (obj instanceof Number) {
|
if (obj instanceof Number) {
|
||||||
return ((Number) obj).longValue();
|
return ((Number) obj).longValue();
|
||||||
@ -34,5 +47,4 @@ public class TimeStampMetric implements SimilarityMetric {
|
|||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user