001 /* ===========================================================
002 * JFreeChart : a free chart library for the Java(tm) platform
003 * ===========================================================
004 *
005 * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
006 *
007 * Project Info: http://www.jfree.org/jfreechart/index.html
008 *
009 * This library is free software; you can redistribute it and/or modify it
010 * under the terms of the GNU Lesser General Public License as published by
011 * the Free Software Foundation; either version 2.1 of the License, or
012 * (at your option) any later version.
013 *
014 * This library is distributed in the hope that it will be useful, but
015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017 * License for more details.
018 *
019 * You should have received a copy of the GNU Lesser General Public
020 * License along with this library; if not, write to the Free Software
021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022 * USA.
023 *
024 * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025 * in the United States and other countries.]
026 *
027 * --------------------
028 * XIntervalSeries.java
029 * --------------------
030 * (C) Copyright 2006, 2007, by Object Refinery Limited.
031 *
032 * Original Author: David Gilbert (for Object Refinery Limited);
033 * Contributor(s): -;
034 *
035 * Changes
036 * -------
037 * 20-Oct-2006 : Version 1 (DG);
038 *
039 */
040
041 package org.jfree.data.xy;
042
043 import org.jfree.data.ComparableObjectItem;
044 import org.jfree.data.ComparableObjectSeries;
045
046 /**
047 * A list of (x, x-low, x-high, y) data items.
048 *
049 * @since 1.0.3
050 *
051 * @see XIntervalSeriesCollection
052 */
053 public class XIntervalSeries extends ComparableObjectSeries {
054
055 /**
056 * Creates a new empty series. By default, items added to the series will
057 * be sorted into ascending order by x-value, and duplicate x-values will
058 * be allowed (these defaults can be modified with another constructor.
059 *
060 * @param key the series key (<code>null</code> not permitted).
061 */
062 public XIntervalSeries(Comparable key) {
063 this(key, true, true);
064 }
065
066 /**
067 * Constructs a new xy-series that contains no data. You can specify
068 * whether or not duplicate x-values are allowed for the series.
069 *
070 * @param key the series key (<code>null</code> not permitted).
071 * @param autoSort a flag that controls whether or not the items in the
072 * series are sorted.
073 * @param allowDuplicateXValues a flag that controls whether duplicate
074 * x-values are allowed.
075 */
076 public XIntervalSeries(Comparable key, boolean autoSort,
077 boolean allowDuplicateXValues) {
078 super(key, autoSort, allowDuplicateXValues);
079 }
080
081 /**
082 * Adds a data item to the series.
083 *
084 * @param x the x-value.
085 * @param y the y-value.
086 * @param xLow the lower bound of the y-interval.
087 * @param xHigh the upper bound of the y-interval.
088 */
089 public void add(double x, double xLow, double xHigh, double y) {
090 super.add(new XIntervalDataItem(x, xLow, xHigh, y), true);
091 }
092
093 /**
094 * Returns the x-value for the specified item.
095 *
096 * @param index the item index.
097 *
098 * @return The x-value (never <code>null</code>).
099 */
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 }