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-2007, 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-2007, by Object Refinery Limited.
  31:  *
  32:  * Original Author:  David Gilbert (for Object Refinery Limited);
  33:  * Contributor(s):   -;
  34:  *
  35:  * Changes
  36:  * -------
  37:  * 17-Nov-2001 : Version 1 (DG);
  38:  * 28-Mar-2002 : Implemented SeriesChangeListener interface (DG);
  39:  * 04-Oct-2002 : Fixed errors reported by Checkstyle (DG);
  40:  * 04-Feb-2003 : Removed redundant methods (DG);
  41:  * 27-Mar-2003 : Implemented Serializable (DG);
  42:  *
  43:  */
  44: 
  45: package org.jfree.data.general;
  46: 
  47: import java.io.Serializable;
  48: 
  49: /**
  50:  * An abstract implementation of the {@link SeriesDataset} interface, 
  51:  * containing a mechanism for registering change listeners.
  52:  */
  53: public abstract class AbstractSeriesDataset extends AbstractDataset
  54:                                             implements SeriesDataset,
  55:                                                        SeriesChangeListener,
  56:                                                        Serializable {
  57: 
  58:     /** For serialization. */
  59:     private static final long serialVersionUID = -6074996219705033171L;
  60:     
  61:     /**
  62:      * Creates a new dataset.
  63:      */
  64:     protected AbstractSeriesDataset() {
  65:         super();
  66:     }
  67: 
  68:     /**
  69:      * Returns the number of series in the dataset.
  70:      *
  71:      * @return The series count.
  72:      */
  73:     public abstract int getSeriesCount();
  74: 
  75:     /**
  76:      * Returns the key for a series.  
  77:      * <p>
  78:      * If <code>series</code> is not within the specified range, the 
  79:      * implementing method should throw an {@link IndexOutOfBoundsException} 
  80:      * (preferred) or an {@link IllegalArgumentException}.
  81:      *
  82:      * @param series  the series index (in the range <code>0</code> to 
  83:      *     <code>getSeriesCount() - 1</code>).
  84:      *
  85:      * @return The series key.
  86:      */
  87:     public abstract Comparable getSeriesKey(int series);
  88:     
  89:     /**
  90:      * Returns the index of the named series, or -1.
  91:      * 
  92:      * @param seriesKey  the series key (<code>null</code> permitted).
  93:      * 
  94:      * @return The index.
  95:      */
  96:     public int indexOf(Comparable seriesKey) {
  97:         int seriesCount = getSeriesCount();
  98:         for (int s = 0; s < seriesCount; s++) {
  99:            if (getSeriesKey(s).equals(seriesKey)) {
 100:                return s;
 101:            }
 102:         }
 103:         return -1;
 104:     }
 105:     
 106:     /**
 107:      * Called when a series belonging to the dataset changes.
 108:      *
 109:      * @param event  information about the change.
 110:      */
 111:     public void seriesChanged(SeriesChangeEvent event) {
 112:         fireDatasetChanged();
 113:     }
 114: 
 115: }