gov.sandia.cognition.learning.algorithm.clustering.hierarchy.BinaryClusterHierarchyNode Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cognitive-foundry Show documentation
Show all versions of cognitive-foundry Show documentation
A single jar with all the Cognitive Foundry components.
/*
* File: BinaryClusterHierarchyNode.java
* Authors: Justin Basilico
* Company: Sandia National Laboratories
* Project: Cognitive Foundry
*
* Copyright October 02, 2008, Sandia Corporation.
* Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
* license for use of this work by or on behalf of the U.S. Government. Export
* of this program may require a license from the United States Government.
* See CopyrightHistory.txt for complete details.
*
*/
package gov.sandia.cognition.learning.algorithm.clustering.hierarchy;
import gov.sandia.cognition.learning.algorithm.clustering.cluster.Cluster;
import java.util.ArrayList;
import java.util.List;
/**
* Implements a binary cluster hierarchy node. It can support two children.
*
* @param
* The type of the data in the cluster.
* @param
* The type of cluster contained in the hierarchy node.
* @author Justin Basilico
* @since 2.1
*/
public class BinaryClusterHierarchyNode>
extends AbstractClusterHierarchyNode
{
/** The first child node. */
protected ClusterHierarchyNode firstChild;
/** The second child node. */
protected ClusterHierarchyNode secondChild;
/**
* Creates a new {@code BinaryClusterHierarchyNode}.
*/
public BinaryClusterHierarchyNode()
{
this(null);
}
/**
* Creates a new {@code BinaryClusterHierarchyNode}.
*
* @param cluster
* The cluster associated with this node.
*/
public BinaryClusterHierarchyNode(
final ClusterType cluster)
{
this(cluster, null, null);
}
/**
* Creates a new {@code BinaryClusterHierarchyNode}.
*
* @param cluster
* The cluster associated with this node.
* @param firstChild
* The first child node.
* @param secondChild
* The second child node.
*/
public BinaryClusterHierarchyNode(
final ClusterType cluster,
final ClusterHierarchyNode firstChild,
final ClusterHierarchyNode secondChild)
{
super(cluster);
this.setFirstChild(firstChild);
this.setSecondChild(secondChild);
}
@Override
public boolean hasChildren()
{
return this.firstChild != null || this.secondChild != null;
}
public List> getChildren()
{
if (!this.hasChildren())
{
// No children.
return null;
}
// Create the result.
final ArrayList> result =
new ArrayList>();
if (this.firstChild != null)
{
result.add(this.firstChild);
}
if (this.secondChild != null)
{
result.add(this.secondChild);
}
return result;
}
/**
* Gets the first child node, if there is one. Otherwise, null is returned.
*
* @return The first child node.
*/
public ClusterHierarchyNode getFirstChild()
{
return this.firstChild;
}
/**
* Sets the first child node.
*
* @param firstChild
* The first child node.
*/
public void setFirstChild(
final ClusterHierarchyNode firstChild)
{
this.firstChild = firstChild;
}
/**
* Gets the second child node, if there is one. Otherwise, null is returned.
*
* @return The second child node.
*/
public ClusterHierarchyNode getSecondChild()
{
return this.secondChild;
}
/**
* Sets the second child node.
*
* @param secondChild
* The second child node.
*/
public void setSecondChild(
final ClusterHierarchyNode secondChild)
{
this.secondChild = secondChild;
}
}