1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-08-13 17:03:45 -04:00
filebot/source/net/filebot/similarity/DateMetric.java

49 lines
776 B
Java
Raw Normal View History

package net.sourceforge.filebot.similarity;
import java.io.File;
import net.sourceforge.filebot.web.SimpleDate;
public class DateMetric implements SimilarityMetric {
private final DateMatcher matcher;
public DateMetric() {
this.matcher = new DateMatcher();
}
public DateMetric(DateMatcher matcher) {
this.matcher = matcher;
}
@Override
public float getSimilarity(Object o1, Object o2) {
SimpleDate d1 = parse(o1);
if (d1 == null)
return 0;
SimpleDate d2 = parse(o2);
if (d2 == null)
return 0;
return d1.equals(d2) ? 1 : -1;
}
public SimpleDate parse(Object object) {
if (object instanceof File) {
// parse file name
object = ((File) object).getName();
}
return matcher.match(object.toString());
}
}