Skip to content
Snippets Groups Projects
Verified Commit 0855b474 authored by David Procházka's avatar David Procházka
Browse files

FIX: getNearestChild cleanup

parent 55c51734
No related branches found
No related tags found
No related merge requests found
......@@ -125,7 +125,7 @@ class BuildTree {
.reduce(Float.MAX_VALUE, Math::min);
Map<Node, Float> nodeToObjectDistance = Arrays.stream(nodes)
.collect(Collectors.toMap(node -> node, getMinHullObjectDistance));
.collect(Collectors.toMap(Function.identity(), getMinHullObjectDistance));
// Add object to the node with minimal distance to this object
Collections.min(nodeToObjectDistance.entrySet(), Map.Entry.comparingByValue()).getKey().addObject(object);
......
......@@ -4,10 +4,8 @@ import cz.muni.fi.disa.similarityoperators.cover.AbstractRepresentation.Precompu
import messif.objects.LocalAbstractObject;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
public class InternalNode extends Node implements Serializable {
......@@ -33,9 +31,10 @@ public class InternalNode extends Node implements Serializable {
}
public Node getNearestChild(LocalAbstractObject object) {
List<Float> distances = children.stream().map(child -> child.getDistance(object)).collect(Collectors.toList());
Map<Node, Float> nodeToObjectDistance = children.stream()
.collect(Collectors.toMap(Function.identity(), node -> node.getDistance(object)));
return children.get(Utils.getIndexOfMinElement(distances));
return Collections.min(nodeToObjectDistance.entrySet(), Map.Entry.comparingByValue()).getKey();
}
public void addObject(LocalAbstractObject object) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment