Skip to content
Snippets Groups Projects
LeafNode.java 2.42 KiB
Newer Older
import cz.muni.fi.disa.similarityoperators.cover.AbstractRepresentation.PrecomputedDistances;
import messif.buckets.BucketStorageException;
import messif.buckets.LocalBucket;
import messif.objects.LocalAbstractObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
 * Represents a leaf node in MH-Tree.

public class LeafNode extends Node implements Serializable {
    /**
     * Serialization ID
     */
    private static final long serialVersionUID = 1L;

    /**
     * Bucket for storing objects of the MH-Tree.
     */
    private final LocalBucket bucket;
    protected LeafNode(PrecomputedDistances distances, LocalBucket bucket, InsertType insertType, ObjectToNodeDistance objectToNodeDistance) throws BucketStorageException {
        super(distances, insertType, objectToNodeDistance);

        this.bucket = bucket;
        this.bucket.addObjects(distances.getObjects());
    /**
     * Adds {@code object} to the node's bucket.
     *
     * @param object object to be added
     * @throws BucketStorageException addition of object into bucket exception
     */
    protected void addObject(LocalAbstractObject object) throws BucketStorageException {
        bucket.addObject(object);
    /**
     * Returns a list of objects in node's bucket.
     *
     * @return a list of objects in node's bucket
     */
    public List<LocalAbstractObject> getObjects() {
        List<LocalAbstractObject> objects = new ArrayList<>(bucket.getObjectCount());
        bucket
                .getAllObjects()
                .forEachRemaining(objects::add);
    /**
     * Returns the number of objects stored in node's bucket.
     *
     * @return the number of objects stored in node's bucket
     */
        return bucket.getObjectCount();
    }

    /**
     * Returns the height of this node.
     *
     * @return the height of this node
     */
    /**
     * Adds this node into {@code nodes}.
     *
     * @param nodes list of nodes
     */
        nodes.add(this);
    }

    /**
     * Adds this node into {@code leafNodes}.
     *
     * @param leafNodes list of leaf nodes
     */
    protected void gatherLeafNodes(List<LeafNode> leafNodes) {
        leafNodes.add(this);