diff --git a/src/mhtree/InternalNode.java b/src/mhtree/InternalNode.java index 65513351a4d71aa728fd8f697d7257a86b15569e..d8a07fa1ef20bca47f5631f6ee77dc344a952850 100644 --- a/src/mhtree/InternalNode.java +++ b/src/mhtree/InternalNode.java @@ -51,21 +51,11 @@ class InternalNode extends Node implements Serializable { return nearestChild.orElseThrow(() -> new IllegalStateException("Internal node has no children")); } - /** - * Adds {@code object} into this node. - * - * @param object object to be added - */ @Override protected void addObject(LocalAbstractObject object) { addObjectIntoHull(object); } - /** - * Returns the list of objects stored in node's descendants. - * - * @return the list of objects stored in node's descendants - */ @Override protected List<LocalAbstractObject> getObjects() { return children @@ -75,11 +65,6 @@ class InternalNode extends Node implements Serializable { .collect(Collectors.toList()); } - /** - * Returns the height of this node. - * - * @return the height of this node - */ @Override protected int getHeight() { return children @@ -89,22 +74,12 @@ class InternalNode extends Node implements Serializable { .getMax() + 1; } - /** - * Adds this node and this node's descendants into {@code nodes}. - * - * @param nodes list of nodes - */ @Override protected void gatherNodes(List<Node> nodes) { nodes.add(this); children.forEach(child -> child.gatherNodes(nodes)); } - /** - * Calls {@code gatherLeafNodes} on every child. - * - * @param leafNodes list of leaf nodes - */ @Override protected void gatherLeafNodes(List<LeafNode> leafNodes) { children.forEach(child -> child.gatherLeafNodes(leafNodes)); diff --git a/src/mhtree/LeafNode.java b/src/mhtree/LeafNode.java index 9cad0e9d1f01fc9bc1e214ca9da5dc9538833f32..ea4ead9d37b12dadcfe770b5ff78f37cbee5ba5b 100644 --- a/src/mhtree/LeafNode.java +++ b/src/mhtree/LeafNode.java @@ -33,22 +33,20 @@ public class LeafNode extends Node implements Serializable { } /** - * Adds {@code object} to the node's bucket. + * Returns the number of objects stored in node's bucket. * - * @param object object to be added - * @throws BucketStorageException addition of object into bucket exception + * @return the number of objects stored in node's bucket */ + protected int getObjectCount() { + return bucket.getObjectCount(); + } + @Override protected void addObject(LocalAbstractObject object) throws BucketStorageException { bucket.addObject(object); addObjectIntoHull(object); } - /** - * Returns a list of objects in node's bucket. - * - * @return a list of objects in node's bucket - */ @Override public List<LocalAbstractObject> getObjects() { List<LocalAbstractObject> objects = new ArrayList<>(bucket.getObjectCount()); @@ -60,40 +58,16 @@ public class LeafNode extends Node implements Serializable { return objects; } - /** - * Returns the number of objects stored in node's bucket. - * - * @return the number of objects stored in node's bucket - */ - protected int getObjectCount() { - return bucket.getObjectCount(); - } - - /** - * Returns the height of this node. - * - * @return the height of this node - */ @Override protected int getHeight() { return 0; } - /** - * Adds this node into {@code nodes}. - * - * @param nodes list of nodes - */ @Override protected void gatherNodes(List<Node> nodes) { nodes.add(this); } - /** - * Adds this node into {@code leafNodes}. - * - * @param leafNodes list of leaf nodes - */ @Override protected void gatherLeafNodes(List<LeafNode> leafNodes) { leafNodes.add(this); diff --git a/src/mhtree/Node.java b/src/mhtree/Node.java index 9b9494fb40fc3893433b444da390c44396c00b68..09d5b3dceb367b37f1dcca965900315787901a6f 100644 --- a/src/mhtree/Node.java +++ b/src/mhtree/Node.java @@ -99,14 +99,40 @@ public abstract class Node implements Serializable { } } + /** + * Adds {@code object} into this node, possibly adding {@code object} to the bucket. + * + * @param object object to be added + * @throws BucketStorageException bucket exception + */ protected abstract void addObject(LocalAbstractObject object) throws BucketStorageException; + /** + * Returns objects from buckets, such that the leaf node is descendants of the current node. + * + * @return objects from buckets, such that the leaf node is descendants of the current node. + */ protected abstract List<LocalAbstractObject> getObjects(); + /** + * Returns the height of this node. + * + * @return the height of this node + */ protected abstract int getHeight(); + /** + * Adds this node and descendants into {@code nodes}. + * + * @param nodes list of nodes + */ protected abstract void gatherNodes(List<Node> nodes); + /** + * Adds every descendant leaf node into {@code leafNodes}. + * + * @param leafNodes list of leaf nodes + */ protected abstract void gatherLeafNodes(List<LeafNode> leafNodes); private void insertGreedy(LocalAbstractObject object) {