diff --git a/src/mhtree/BuildTree.java b/src/mhtree/BuildTree.java index cf0e98cef4259471616fc395f637ecf6199deafc..b8b7c9f3ab94be0228dfee123638d364a17a1aa3 100644 --- a/src/mhtree/BuildTree.java +++ b/src/mhtree/BuildTree.java @@ -127,14 +127,9 @@ class BuildTree { private void addObjectToClosestNode(int objectIndex) throws BucketStorageException { LocalAbstractObject object = objectDistances.getObject(objectIndex); - Function<Node, Float> getMinHullObjectDistance = node -> node.getHullObjects().stream() - .map(object::getDistance) - .reduce(Float.MAX_VALUE, Math::min); + Map<Node, Double> nodeToObjectDistance = Arrays.stream(nodes) + .collect(Collectors.toMap(Function.identity(), node -> node.getDistance(object))); - Map<Node, Float> nodeToObjectDistance = Arrays.stream(nodes) - .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); }