diff --git a/src/mhtree/InternalNode.java b/src/mhtree/InternalNode.java index 887500605c0e1d6c71df07a83d7d88e3fd54037c..1db84f2d1ecf3a104ca7515638d857d36aa3c2ad 100644 --- a/src/mhtree/InternalNode.java +++ b/src/mhtree/InternalNode.java @@ -1,6 +1,5 @@ package mhtree; -import messif.buckets.BucketStorageException; import messif.objects.LocalAbstractObject; import java.io.Serializable; @@ -9,7 +8,6 @@ import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; -import java.util.stream.Stream; public class InternalNode extends Node implements Serializable { @@ -20,7 +18,7 @@ public class InternalNode extends Node implements Serializable { private List<Node> children; - InternalNode(Stream<LocalAbstractObject> objects) { + InternalNode(List<LocalAbstractObject> objects) { super(objects); children = new ArrayList<>(); } @@ -51,4 +49,12 @@ public class InternalNode extends Node implements Serializable { .flatMap(Collection::stream) .collect(Collectors.toList()); } + + public boolean contains(LocalAbstractObject object) { + for (Node child : children) + if (child.contains(object)) + return true; + + return false; + } } diff --git a/src/mhtree/LeafNode.java b/src/mhtree/LeafNode.java index 796fd00d604725b61dc9db5f56a0bf97fbe35077..2704c452cdab865adf86248d4b52ac5eabbed172 100644 --- a/src/mhtree/LeafNode.java +++ b/src/mhtree/LeafNode.java @@ -45,4 +45,12 @@ public class LeafNode extends Node implements Serializable { return objects; } + + public boolean contains(LocalAbstractObject object) { + for (AbstractObjectIterator<LocalAbstractObject> it = bucket.getAllObjects(); it.hasNext(); ) + if (object == it.next()) + return true; + + return false; + } } diff --git a/src/mhtree/Node.java b/src/mhtree/Node.java index 71eb2246104c08e2b5e109e08ec93f988ea08964..cca22eb8f7309fc00019a81129c1db3e841c07f4 100644 --- a/src/mhtree/Node.java +++ b/src/mhtree/Node.java @@ -8,7 +8,6 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; -import java.util.stream.Stream; public abstract class Node implements Serializable { @@ -29,12 +28,10 @@ public abstract class Node implements Serializable { this(new HullOptimizedRepresentationV3(objects)); } - Node(Stream<LocalAbstractObject> objects) { - this(new HullOptimizedRepresentationV3(objects.collect(Collectors.toList()))); - } - public static InternalNode createParent(List<Node> nodes) { - return new InternalNode(nodes.stream().flatMap(node -> node.getObjects().stream())); + return new InternalNode(nodes.stream() + .flatMap(node -> node.getObjects().stream()) + .collect(Collectors.toList())); } public float getDistance(LocalAbstractObject object) { @@ -51,10 +48,6 @@ public abstract class Node implements Serializable { return (this instanceof LeafNode); } - public boolean contains(LocalAbstractObject object) { - return hull.getObjects().contains(object); - } - public void setParent(Node parent) { this.parent = parent; } @@ -69,8 +62,11 @@ public abstract class Node implements Serializable { } public abstract void addObject(LocalAbstractObject object) throws BucketStorageException; + public abstract List<LocalAbstractObject> getObjects(); + public abstract boolean contains(LocalAbstractObject object); + protected void rebuildHull(LocalAbstractObject object) { List<LocalAbstractObject> objects = new ArrayList<>(getObjects()); objects.add(object);