All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gov.sandia.cognition.learning.algorithm.clustering.cluster.DefaultCluster Maven / Gradle / Ivy

There is a newer version: 4.0.1
Show newest version
/*
 * File:                CentroidCluster.java
 * Authors:             Justin Basilico and Kevin R. Dixon
 * Company:             Sandia National Laboratories
 * Project:             Cognitive Foundry
 *
 * Copyright February 22, 2006, 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.cluster;

import gov.sandia.cognition.annotation.CodeReview;
import gov.sandia.cognition.util.AbstractCloneableSerializable;
import gov.sandia.cognition.util.ObjectUtil;
import java.util.ArrayList;
import java.util.Collection;

/**
 * The DefaultCluster class implements a default cluster which contains a
 * list of members in an ArrayList along with an index that identifies the
 * cluster.
 *
 * @param   The type of data stored in the cluster.
 * @author Justin Basilico
 * @author Kevin R. Dixon
 * @since  1.0
 */
@CodeReview(
    reviewer="Kevin R. Dixon",
    date="2008-07-22",
    changesNeeded=false,
    comments="Interface looks fine."
)
public class DefaultCluster
    extends AbstractCloneableSerializable
    implements Cluster
{
    /** The default index is {@value}. */
    public static final int DEFAULT_INDEX = -1;
    
    /** The index of the cluster in the collection of clusters. */
    private int index;
    
    /** The members of the cluster. */
    private ArrayList members;
    
    /**
     * Creates a new instance of CentroidCluster.
     */
    public DefaultCluster()
    {
        this(null);
    }
    
    /**
     * Creates a new instance of CentroidCluster.
     *
     * @param index The index of the cluster.
     */
    public DefaultCluster(
        final int index)
    {
        this(index, null);
    }
    
    /**
     * Creates a new instance of CentroidCluster.
     *
     * @param members The members of the cluster.
     */
    public DefaultCluster(
        final Collection members)
    {
        this(DEFAULT_INDEX, members);
    }
    
    /**
     * Creates a new instance of CentroidCluster.
     *
     * @param index The index of the cluster.
     * @param members The members of the cluster.
     */
    public DefaultCluster(
        final int index,
        final Collection members)
    {
        super();
        
        this.setIndex(index);
        
        if ( members == null )
        {
            // No members so use an empty array.
            this.setMembers(new ArrayList());
        }
        else
        {
            // Create a copy of the given members list.
            this.setMembers(new ArrayList(members));
        }
    }

    @Override
    public DefaultCluster clone()
    {
        @SuppressWarnings("unchecked")
        DefaultCluster clone =
            (DefaultCluster) super.clone();
        clone.setMembers( ObjectUtil.cloneSmart( this.getMembers() ) );
        return clone;
    }
    
    /**
     * Gets the cluster index.
     *
     * @return The index of the cluster.
     */
    public int getIndex()
    {
        return this.index;
    }
    
    /**
     * Gets the members of the cluster.
     *
     * @return The members of the cluster.
     */
    public ArrayList getMembers()
    {
        return this.members;
    }
    
    /**
     * Sets the index of the cluster.
     *
     * @param index The new index.
     */
    public void setIndex(
        final int index)
    {
        this.index = index;
    }
    
    /**
     * Sets the members of the cluster.
     *
     * @param members The new members of the cluster.
     */
    private void setMembers(
        final ArrayList members)
    {
        this.members = members;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy