Source for org.jfree.data.xy.XIntervalSeries

   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:  * XIntervalSeries.java
  29:  * --------------------
  30:  * (C) Copyright 2006, 2007, by Object Refinery Limited.
  31:  *
  32:  * Original Author:  David Gilbert (for Object Refinery Limited);
  33:  * Contributor(s):   -;
  34:  *
  35:  * Changes
  36:  * -------
  37:  * 20-Oct-2006 : Version 1 (DG);
  38:  *
  39:  */
  40: 
  41: package org.jfree.data.xy;
  42: 
  43: import org.jfree.data.ComparableObjectItem;
  44: import org.jfree.data.ComparableObjectSeries;
  45: 
  46: /**
  47:  * A list of (x, x-low, x-high, y) data items.
  48:  *
  49:  * @since 1.0.3
  50:  *
  51:  * @see XIntervalSeriesCollection
  52:  */
  53: public class XIntervalSeries extends ComparableObjectSeries {
  54:     
  55:     /**
  56:      * Creates a new empty series.  By default, items added to the series will 
  57:      * be sorted into ascending order by x-value, and duplicate x-values will 
  58:      * be allowed (these defaults can be modified with another constructor.
  59:      *
  60:      * @param key  the series key (<code>null</code> not permitted).
  61:      */
  62:     public XIntervalSeries(Comparable key) {
  63:         this(key, true, true);
  64:     }
  65:     
  66:     /**
  67:      * Constructs a new xy-series that contains no data.  You can specify 
  68:      * whether or not duplicate x-values are allowed for the series.
  69:      *
  70:      * @param key  the series key (<code>null</code> not permitted).
  71:      * @param autoSort  a flag that controls whether or not the items in the 
  72:      *                  series are sorted.
  73:      * @param allowDuplicateXValues  a flag that controls whether duplicate 
  74:      *                               x-values are allowed.
  75:      */
  76:     public XIntervalSeries(Comparable key, boolean autoSort, 
  77:             boolean allowDuplicateXValues) {
  78:         super(key, autoSort, allowDuplicateXValues);
  79:     }
  80:     
  81:     /**
  82:      * Adds a data item to the series.
  83:      *
  84:      * @param x  the x-value.
  85:      * @param y  the y-value.
  86:      * @param xLow  the lower bound of the y-interval.
  87:      * @param xHigh  the upper bound of the y-interval.
  88:      */
  89:     public void add(double x, double xLow, double xHigh, double y) {
  90:         super.add(new XIntervalDataItem(x, xLow, xHigh, y), true);
  91:     }
  92:     
  93:     /**
  94:      * Returns the x-value for the specified item.
  95:      *
  96:      * @param index  the item index.
  97:      *
  98:      * @return The x-value (never <code>null</code>).
  99:      */
 100:     public Number getX(int index) {
 101:         XIntervalDataItem item = (XIntervalDataItem) getDataItem(index);
 102:         return item.getX();
 103:     }
 104:     
 105:     /**
 106:      * Returns the y-value for the specified item.
 107:      *
 108:      * @param index  the item index.
 109:      *
 110:      * @return The y-value.
 111:      */
 112:     public double getYValue(int index) {
 113:         XIntervalDataItem item = (XIntervalDataItem) getDataItem(index);
 114:         return item.getYValue();
 115:     }
 116:     
 117:     /**
 118:      * Returns the data item at the specified index.
 119:      * 
 120:      * @param index  the item index.
 121:      * 
 122:      * @return The data item.
 123:      */
 124:     public ComparableObjectItem getDataItem(int index) {
 125:         return super.getDataItem(index);
 126:     }
 127:     
 128: }