filebot/source/net/filebot/similarity/FileNameMetric.java

36 lines
663 B
Java
Raw Normal View History

2014-04-19 02:30:29 -04:00
package net.filebot.similarity;
2014-04-19 02:30:29 -04:00
import static net.filebot.util.FileUtilities.*;
import java.io.File;
public class FileNameMetric implements SimilarityMetric {
2015-07-25 18:47:19 -04:00
@Override
public float getSimilarity(Object o1, Object o2) {
String s1 = getFileName(o1);
if (s1 == null || s1.isEmpty())
return 0;
2015-07-25 18:47:19 -04:00
String s2 = getFileName(o2);
if (s2 == null || s2.isEmpty())
return 0;
2015-07-25 18:47:19 -04:00
return s1.startsWith(s2) || s2.startsWith(s1) ? 1 : 0;
}
2015-07-25 18:47:19 -04:00
protected String getFileName(Object object) {
if (object instanceof File) {
// name without extension normalized to lower-case
return getName((File) object).trim().toLowerCase();
}
2015-07-25 18:47:19 -04:00
return null;
}
2015-07-25 18:47:19 -04:00
}