Source for org.jfree.data.general.AbstractSeriesDataset

   1: /* ===========================================================
   2:  * JFreeChart : a free chart library for the Java(tm) platform
   3:  * ===========================================================
   4:  *
   5:  * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors.
   6:  *
   7:  * Project Info:  http://www.jfree.org/jfreechart/index.html
   8:  *
   9:  * This library is free software; you can redistribute it and/or modify it 
  10:  * under the terms of the GNU Lesser General Public License as published by 
  11:  * the Free Software Foundation; either version 2.1 of the License, or 
  12:  * (at your option) any later version.
  13:  *
  14:  * This library is distributed in the hope that it will be useful, but 
  15:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
  16:  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
  17:  * License for more details.
  18:  *
  19:  * You should have received a copy of the GNU Lesser General Public
  20:  * License along with this library; if not, write to the Free Software
  21:  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
  22:  * USA.  
  23:  *
  24:  * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
  25:  * in the United States and other countries.]
  26:  *
  27:  * --------------------------
  28:  * AbstractSeriesDataset.java
  29:  * --------------------------
  30:  * (C) Copyright 2001-2006, by Object Refinery Limited.
  31:  *
  32:  * Original Author:  David Gilbert (for Object Refinery Limited);
  33:  * Contributor(s):   -;
  34:  *
  35:  * $Id: AbstractSeriesDataset.java,v 1.4.2.3 2006/08/03 16:07:03 mungady Exp $
  36:  *
  37:  * Changes
  38:  * -------
  39:  * 17-Nov-2001 : Version 1 (DG);
  40:  * 28-Mar-2002 : Implemented SeriesChangeListener interface (DG);
  41:  * 04-Oct-2002 : Fixed errors reported by Checkstyle (DG);
  42:  * 04-Feb-2003 : Removed redundant methods (DG);
  43:  * 27-Mar-2003 : Implemented Serializable (DG);
  44:  *
  45:  */
  46: 
  47: package org.jfree.data.general;
  48: 
  49: import java.io.Serializable;
  50: 
  51: /**
  52:  * An abstract implementation of the {@link SeriesDataset} interface, 
  53:  * containing a mechanism for registering change listeners.
  54:  */
  55: public abstract class AbstractSeriesDataset extends AbstractDataset
  56:                                             implements SeriesDataset,
  57:                                                        SeriesChangeListener,
  58:                                                        Serializable {
  59: 
  60:     /** For serialization. */
  61:     private static final long serialVersionUID = -6074996219705033171L;
  62:     
  63:     /**
  64:      * Creates a new dataset.
  65:      */
  66:     protected AbstractSeriesDataset() {
  67:         super();
  68:     }
  69: 
  70:     /**
  71:      * Returns the number of series in the dataset.
  72:      *
  73:      * @return The series count.
  74:      */
  75:     public abstract int getSeriesCount();
  76: 
  77:     /**
  78:      * Returns the key for a series.  
  79:      * <p>
  80:      * If <code>series</code> is not within the specified range, the 
  81:      * implementing method should throw an {@link IndexOutOfBoundsException} 
  82:      * (preferred) or an {@link IllegalArgumentException}.
  83:      *
  84:      * @param series  the series index (in the range <code>0</code> to 
  85:      *     <code>getSeriesCount() - 1</code>).
  86:      *
  87:      * @return The series key.
  88:      */
  89:     public abstract Comparable getSeriesKey(int series);
  90:     
  91:     /**
  92:      * Returns the index of the named series, or -1.
  93:      * 
  94:      * @param seriesKey  the series key (<code>null</code> permitted).
  95:      * 
  96:      * @return The index.
  97:      */
  98:     public int indexOf(Comparable seriesKey) {
  99:         int seriesCount = getSeriesCount();
 100:         for (int s = 0; s < seriesCount; s++) {
 101:            if (getSeriesKey(s).equals(seriesKey)) {
 102:                return s;
 103:            }
 104:         }
 105:         return -1;
 106:     }
 107:     
 108:     /**
 109:      * Called when a series belonging to the dataset changes.
 110:      *
 111:      * @param event  information about the change.
 112:      */
 113:     public void seriesChanged(SeriesChangeEvent event) {
 114:         fireDatasetChanged();
 115:     }
 116: 
 117: }