Newer
Older

David Procházka
committed
import cz.muni.fi.disa.similarityoperators.cover.AbstractRepresentation.PrecomputedDistances;
import messif.objects.LocalAbstractObject;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
* Represents an internal node in MH-Tree.
class InternalNode extends Node implements Serializable {
/**
* Serialization ID
*/
private static final long serialVersionUID = 2L;

David Procházka
committed
protected InternalNode(PrecomputedDistances distances, InsertType insertType, ObjectToNodeDistance objectToNodeDistance, List<Node> children) {
super(distances, insertType, objectToNodeDistance);
/**
* Returns the list of child nodes.
*
* @return the list of child nodes
*/

David Procházka
committed
protected List<Node> getChildren() {
return children;
/**
* Returns the nearest child to the {@code object}.
*
* @param object object to which the distance is measured
* @return the nearest child to the {@code object}
*/

David Procházka
committed
protected Node getNearestChild(LocalAbstractObject object) {
Node nearestChild = children.get(0);
double minDistance = nearestChild.getDistance(object);

David Procházka
committed
for (int i = 1; i < children.size(); i++) {
double distance = children.get(i).getDistance(object);
if (distance < minDistance) {
minDistance = distance;

David Procházka
committed
nearestChild = children.get(i);
/**
* Adds {@code object} into this node.
*
* @param object object to be added
*/

David Procházka
committed
protected void addObject(LocalAbstractObject object) {
/**
* Returns the list of objects stored in node's descendants.
*
* @return the list of objects stored in node's descendants
*/

David Procházka
committed
protected List<LocalAbstractObject> getObjects() {
.map(Node::getObjects)
.flatMap(Collection::stream)
/**
* Returns the height of this node.
*
* @return the height of this node
*/

David Procházka
committed
protected int getHeight() {
.mapToInt(Node::getHeight)
.summaryStatistics()
.getMax() + 1;
}
/**
* Adds this node and this node's descendants into {@code nodes}.
*

David Procházka
committed
protected void gatherNodes(List<Node> nodes) {
nodes.add(this);
nodes.addAll(children);
}
* Calls {@code gatherLeafNodes} on every child.

David Procházka
committed
protected void gatherLeafNodes(List<LeafNode> leafNodes) {
children.forEach(child -> child.gatherLeafNodes(leafNodes));