Home | History | Annotate | Download | only in clustering
      1 /*
      2  * Licensed to the Apache Software Foundation (ASF) under one or more
      3  * contributor license agreements.  See the NOTICE file distributed with
      4  * this work for additional information regarding copyright ownership.
      5  * The ASF licenses this file to You under the Apache License, Version 2.0
      6  * (the "License"); you may not use this file except in compliance with
      7  * the License.  You may obtain a copy of the License at
      8  *
      9  *      http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 package org.apache.commons.math.stat.clustering;
     19 
     20 import java.io.Serializable;
     21 import java.util.ArrayList;
     22 import java.util.List;
     23 
     24 /**
     25  * Cluster holding a set of {@link Clusterable} points.
     26  * @param <T> the type of points that can be clustered
     27  * @version $Revision: 771076 $ $Date: 2009-05-03 18:28:48 +0200 (dim. 03 mai 2009) $
     28  * @since 2.0
     29  */
     30 public class Cluster<T extends Clusterable<T>> implements Serializable {
     31 
     32     /** Serializable version identifier. */
     33     private static final long serialVersionUID = -3442297081515880464L;
     34 
     35     /** The points contained in this cluster. */
     36     private final List<T> points;
     37 
     38     /** Center of the cluster. */
     39     private final T center;
     40 
     41     /**
     42      * Build a cluster centered at a specified point.
     43      * @param center the point which is to be the center of this cluster
     44      */
     45     public Cluster(final T center) {
     46         this.center = center;
     47         points = new ArrayList<T>();
     48     }
     49 
     50     /**
     51      * Add a point to this cluster.
     52      * @param point point to add
     53      */
     54     public void addPoint(final T point) {
     55         points.add(point);
     56     }
     57 
     58     /**
     59      * Get the points contained in the cluster.
     60      * @return points contained in the cluster
     61      */
     62     public List<T> getPoints() {
     63         return points;
     64     }
     65 
     66     /**
     67      * Get the point chosen to be the center of this cluster.
     68      * @return chosen cluster center
     69      */
     70     public T getCenter() {
     71         return center;
     72     }
     73 
     74 }
     75