From 326edb28fce0a0603091d797bc3d004809bc5a7f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Proch=C3=A1zka?= <david@prochazka.dev>
Date: Mon, 15 Mar 2021 17:07:26 +0100
Subject: [PATCH] ADD: leaf node javadoc

---
 src/mhtree/InternalNode.java | 16 +++-----
 src/mhtree/LeafNode.java     | 71 +++++++++++++++++++++++++++++-------
 2 files changed, 64 insertions(+), 23 deletions(-)

diff --git a/src/mhtree/InternalNode.java b/src/mhtree/InternalNode.java
index e409850..44ca059 100644
--- a/src/mhtree/InternalNode.java
+++ b/src/mhtree/InternalNode.java
@@ -11,7 +11,7 @@ import java.util.stream.Collectors;
 /**
  * Represents internal node of MH-Tree, i.e. a non-leaf node.
  */
-public class InternalNode extends Node implements Serializable {
+class InternalNode extends Node implements Serializable {
 
     /**
      * Serialization ID
@@ -98,7 +98,7 @@ public class InternalNode extends Node implements Serializable {
     /**
      * Adds this node and this node's descendants into {@code nodes}.
      *
-     * @param nodes list of nodes, where gathered nodes are added
+     * @param nodes list of nodes
      */
     void gatherNodes(List<Node> nodes) {
         nodes.add(this);
@@ -106,16 +106,12 @@ public class InternalNode extends Node implements Serializable {
     }
 
     /**
-     * Returns a list of leaf nodes under this node.
+     * Calls {@code gatherLeafNodes} on every child.
      *
-     * @return a list of leaf node under this node
+     * @param leafNodes list of leaf nodes
      */
-    List<LeafNode> getLeafNodes() {
-        return children
-                .stream()
-                .map(Node::getLeafNodes)
-                .flatMap(Collection::stream)
-                .collect(Collectors.toList());
+    void gatherLeafNodes(List<LeafNode> leafNodes) {
+        children.forEach(child -> child.gatherLeafNodes(leafNodes));
     }
 
     /**
diff --git a/src/mhtree/LeafNode.java b/src/mhtree/LeafNode.java
index 238222b..e11bd7e 100644
--- a/src/mhtree/LeafNode.java
+++ b/src/mhtree/LeafNode.java
@@ -7,18 +7,23 @@ import messif.objects.LocalAbstractObject;
 import messif.objects.util.AbstractObjectIterator;
 
 import java.io.Serializable;
-import java.util.Collections;
-import java.util.HashSet;
+import java.util.ArrayList;
 import java.util.List;
-import java.util.Set;
 
-public class LeafNode extends Node implements Serializable {
+/**
+ * Represents leaf node of MH-Tree.
+ */
+class LeafNode extends Node implements Serializable {
 
     /**
      * Serialization ID
      */
     private static final long serialVersionUID = 1L;
-    private LocalBucket bucket;
+
+    /**
+     * Bucket for storing objects of the MH-Tree.
+     */
+    private final LocalBucket bucket;
 
     LeafNode(PrecomputedDistances distances, LocalBucket bucket, InsertType insertType, ObjectToNodeDistance objectToNodeDistance) throws BucketStorageException {
         super(distances, insertType, objectToNodeDistance);
@@ -27,26 +32,66 @@ public class LeafNode extends Node implements Serializable {
         this.bucket.addObjects(distances.getObjects());
     }
 
-    public void addObject(LocalAbstractObject object) throws BucketStorageException {
+    /**
+     * Adds {@code object} to the node's bucket.
+     *
+     * @param object object to be added
+     * @throws BucketStorageException addition of object into bucket exception
+     */
+    void addObject(LocalAbstractObject object) throws BucketStorageException {
         bucket.addObject(object);
 
-        addNewObject(object);
+        addObjectIntoHull(object);
     }
 
-    public Set<LocalAbstractObject> getObjects() {
-        Set<LocalAbstractObject> objects = new HashSet<>(bucket.getObjectCount());
+    /**
+     * Returns a list of objects in node's bucket.
+     *
+     * @return a list of objects in node's bucket
+     */
+    List<LocalAbstractObject> getObjects() {
+        List<LocalAbstractObject> objects = new ArrayList<>(bucket.getObjectCount());
 
-        for (AbstractObjectIterator<LocalAbstractObject> it = bucket.getAllObjects(); it.hasNext(); )
+        for (AbstractObjectIterator<LocalAbstractObject> it = bucket.getAllObjects(); it.hasNext(); ) {
             objects.add(it.next());
+        }
 
         return objects;
     }
 
-    public int getHeight() {
+    /**
+     * Returns the number of objects stored in node's bucket.
+     *
+     * @return the number of objects stored in node's bucket
+     */
+    int getObjectCount() {
+        return bucket.getObjectCount();
+    }
+
+    /**
+     * Returns the height of this node.
+     *
+     * @return the height of this node
+     */
+    int getHeight() {
         return 0;
     }
 
-    public List<Node> getNodesOnLevel(int level) {
-        return Collections.singletonList(this);
+    /**
+     * Adds this node into {@code nodes}.
+     *
+     * @param nodes list of nodes
+     */
+    void gatherNodes(List<Node> nodes) {
+        nodes.add(this);
+    }
+
+    /**
+     * Adds this node into {@code leafNodes}.
+     *
+     * @param leafNodes list of leaf nodes
+     */
+    void gatherLeafNodes(List<LeafNode> leafNodes) {
+        leafNodes.add(this);
     }
 }
-- 
GitLab