Refactor
This commit is contained in:
parent
331b271d2b
commit
ce64a653f0
|
@ -17,8 +17,6 @@ import java.nio.file.SimpleFileVisitor;
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -374,18 +372,15 @@ public class ScriptShellMethods {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Collection<?> sortBySimilarity(Collection<?> self, final Object prime, final Closure<String> toStringFunction) {
|
public static Collection<?> sortBySimilarity(Collection<?> self, final Object prime, final Closure<String> toStringFunction) {
|
||||||
final SimilarityMetric metric = new NameSimilarityMetric();
|
|
||||||
List<Object> values = new ArrayList<Object>(self);
|
List<Object> values = new ArrayList<Object>(self);
|
||||||
Collections.sort(values, new Comparator<Object>() {
|
|
||||||
|
|
||||||
@Override
|
SimilarityMetric metric = new NameSimilarityMetric();
|
||||||
public int compare(Object o1, Object o2) {
|
values.sort((o1, o2) -> {
|
||||||
String s1 = toStringFunction != null ? toStringFunction.call(o1) : o1.toString();
|
String s1 = toStringFunction != null ? toStringFunction.call(o1) : o1.toString();
|
||||||
String s2 = toStringFunction != null ? toStringFunction.call(o2) : o2.toString();
|
String s2 = toStringFunction != null ? toStringFunction.call(o2) : o2.toString();
|
||||||
|
|
||||||
return Float.compare(metric.getSimilarity(s2, prime), metric.getSimilarity(s1, prime));
|
return Float.compare(metric.getSimilarity(s2, prime), metric.getSimilarity(s1, prime));
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue