@SuppressWarnings("unchecked")
@Override
Collection<Resource> select(ReadGraph graph, Collection<Resource> elements) {
- List<Resource> result = new ArrayList<>(elements);
List<Tuple2> result2 = Lists.map(new FunctionImpl1<Resource, Tuple2>() {
@Override
public Tuple2 apply(Resource r) {
return new Tuple2(r, getPropertyValue(graph, r, propertyName));
}
- }, result);
+ }, new ArrayList<>(elements));
result2 = Lists.filter(new FunctionImpl1<Tuple2, Boolean>() {
@Override
result2.sort((t1, t2) -> smallest ? Double.compare((Double) t1.c1, (Double) t2.c1) : Double.compare((Double) t2.c1, (Double) t1.c1));
- if (resultCount < result2.size())
- result2 = result2.subList(0, resultCount);
+ if (resultCount < result2.size()) {
+ double limitValue = (double) result2.get(resultCount-1).c1;
+
+ // Expand selection to contain all items with the same value as the nth one
+ int count = resultCount;
+ while (count < result2.size() && (double)result2.get(count).c1 == limitValue) count++;
+ result2 = result2.subList(0, count);
+ }
- result = Lists.map(new FunctionImpl1<Tuple2, Resource>() {
+ return (List<Resource>) Lists.map(new FunctionImpl1<Tuple2, Resource>() {
@Override
public Resource apply(Tuple2 p0) {
return (Resource) p0.c0;
}
}, result2);
-
- return result;
}
}