2010-10-24 12:33:38 -04:00
|
|
|
|
|
|
|
package net.sourceforge.filebot.similarity;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
2014-04-19 01:39:52 -04:00
|
|
|
import net.sourceforge.filebot.web.SimpleDate;
|
2010-10-24 12:33:38 -04:00
|
|
|
|
|
|
|
|
|
|
|
public class DateMetric implements SimilarityMetric {
|
|
|
|
|
2012-02-09 08:50:14 -05:00
|
|
|
private final DateMatcher matcher;
|
2010-10-24 12:33:38 -04:00
|
|
|
|
2011-12-22 14:36:31 -05:00
|
|
|
|
2010-10-24 12:33:38 -04:00
|
|
|
public DateMetric() {
|
2012-02-09 08:50:14 -05:00
|
|
|
this.matcher = new DateMatcher();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public DateMetric(DateMatcher matcher) {
|
|
|
|
this.matcher = matcher;
|
2010-10-24 12:33:38 -04:00
|
|
|
}
|
|
|
|
|
2011-12-22 14:36:31 -05:00
|
|
|
|
2010-10-24 12:33:38 -04:00
|
|
|
@Override
|
|
|
|
public float getSimilarity(Object o1, Object o2) {
|
2014-04-19 01:39:52 -04:00
|
|
|
SimpleDate d1 = parse(o1);
|
2011-11-27 09:35:53 -05:00
|
|
|
if (d1 == null)
|
|
|
|
return 0;
|
|
|
|
|
2014-04-19 01:39:52 -04:00
|
|
|
SimpleDate d2 = parse(o2);
|
2011-11-27 09:35:53 -05:00
|
|
|
if (d2 == null)
|
|
|
|
return 0;
|
2010-10-24 12:33:38 -04:00
|
|
|
|
2011-11-27 09:35:53 -05:00
|
|
|
return d1.equals(d2) ? 1 : -1;
|
2010-10-24 12:33:38 -04:00
|
|
|
}
|
|
|
|
|
2011-12-22 14:36:31 -05:00
|
|
|
|
2014-04-19 01:39:52 -04:00
|
|
|
public SimpleDate parse(Object object) {
|
2010-10-24 12:33:38 -04:00
|
|
|
if (object instanceof File) {
|
|
|
|
// parse file name
|
|
|
|
object = ((File) object).getName();
|
|
|
|
}
|
|
|
|
|
2012-02-09 08:50:14 -05:00
|
|
|
return matcher.match(object.toString());
|
2010-10-24 12:33:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|