1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-11 11:55:03 -05:00
filebot/source/net/filebot/similarity/FileNameMetric.java
2014-04-19 06:06:45 +00:00

36 lines
696 B
Java

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