    001    /*
    002     * Licensed to the Apache Software Foundation (ASF) under one or more
    003     * contributor license agreements.  See the NOTICE file distributed with
    004     * this work for additional information regarding copyright ownership.
    005     * The ASF licenses this file to You under the Apache License, Version 2.0
    006     * (the "License"); you may not use this file except in compliance with
    007     * the License.  You may obtain a copy of the License at
    008     *
    009     *      http://www.apache.org/licenses/LICENSE-2.0
    010     *
    011     * Unless required by applicable law or agreed to in writing, software
    012     * distributed under the License is distributed on an "AS IS" BASIS,
    013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014     * See the License for the specific language governing permissions and
    015     * limitations under the License.
    016     */
    017
    018    package org.apache.commons.math.stat.clustering;
    019
    020    import java.io.Serializable;
    021    import java.util.ArrayList;
    022    import java.util.List;
    023
    024    /**
    025     * Cluster holding a set of {@link Clusterable} points.
    026     * @param <T> the type of points that can be clustered
    027     * @version $Revision: 771076 $ $Date: 2009-05-03 18:28:48 +0200 (dim. 03 mai 2009) $
    028     * @since 2.0
    029     */
    030    public class Cluster<T extends Clusterable<T>> implements Serializable {
    031
    032        /** Serializable version identifier. */
    033        private static final long serialVersionUID = -3442297081515880464L;
    034
    035        /** The points contained in this cluster. */
    036        private final List<T> points;
    037
    038        /** Center of the cluster. */
    039        private final T center;
    040
    041        /**
    042         * Build a cluster centered at a specified point.
    043         * @param center the point which is to be the center of this cluster
    044         */
    045        public Cluster(final T center) {
    046            this.center = center;
    047            points = new ArrayList<T>();
    048        }
    049
    050        /**
    051         * Add a point to this cluster.
    052         * @param point point to add
    053         */
    054        public void addPoint(final T point) {
    055            points.add(point);
    056        }
    057
    058        /**
    059         * Get the points contained in the cluster.
    060         * @return points contained in the cluster
    061         */
    062        public List<T> getPoints() {
    063            return points;
    064        }
    065
    066        /**
    067         * Get the point chosen to be the center of this cluster.
    068         * @return chosen cluster center
    069         */
    070        public T getCenter() {
    071            return center;
    072        }
    073
    074    }