001/* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2022, by David Gilbert 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 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 025 * Other names may be trademarks of their respective owners.] 026 * 027 * -------------------- 028 * XIntervalSeries.java 029 * -------------------- 030 * (C) Copyright 2006-2022, by David Gilbert. 031 * 032 * Original Author: David Gilbert; 033 * Contributor(s): -; 034 * 035 * Changes 036 * ------- 037 * 20-Oct-2006 : Version 1 (DG); 038 * 11-Apr-2008 : Added getXLowValue() and getXHighValue() methods (DG); 039 * 09-Jan-2014 : Added add(XIntervalDataItem, boolean) method (DG); 040 * 041 */ 042 043package org.jfree.data.xy; 044 045import org.jfree.data.ComparableObjectItem; 046import org.jfree.data.ComparableObjectSeries; 047import org.jfree.data.general.SeriesChangeEvent; 048 049/** 050 * A list of (x, x-low, x-high, y) data items. 051 * 052 * @since 1.0.3 053 * 054 * @see XIntervalSeriesCollection 055 */ 056public class XIntervalSeries<S extends Comparable<S>> 057 extends ComparableObjectSeries<S> { 058 059 /** 060 * Creates a new empty series. By default, items added to the series will 061 * be sorted into ascending order by x-value, and duplicate x-values will 062 * be allowed (these defaults can be modified with another constructor. 063 * 064 * @param key the series key ({@code null} not permitted). 065 */ 066 public XIntervalSeries(S key) { 067 this(key, true, true); 068 } 069 070 /** 071 * Constructs a new xy-series that contains no data. You can specify 072 * whether or not duplicate x-values are allowed for the series. 073 * 074 * @param key the series key ({@code null} not permitted). 075 * @param autoSort a flag that controls whether or not the items in the 076 * series are sorted. 077 * @param allowDuplicateXValues a flag that controls whether duplicate 078 * x-values are allowed. 079 */ 080 public XIntervalSeries(S key, boolean autoSort, 081 boolean allowDuplicateXValues) { 082 super(key, autoSort, allowDuplicateXValues); 083 } 084 085 /** 086 * Adds a data item to the series and sends a {@link SeriesChangeEvent} to 087 * all registered listeners. 088 * 089 * @param x the x-value. 090 * @param y the y-value. 091 * @param xLow the lower bound of the y-interval. 092 * @param xHigh the upper bound of the y-interval. 093 */ 094 public void add(double x, double xLow, double xHigh, double y) { 095 add(new XIntervalDataItem(x, xLow, xHigh, y), true); 096 } 097 098 /** 099 * Adds a data item to the series and, if requested, sends a 100 * {@link SeriesChangeEvent} to all registered listeners. 101 * 102 * @param item the data item ({@code null} not permitted). 103 * @param notify notify listeners? 104 * 105 * @since 1.0.18 106 */ 107 public void add(XIntervalDataItem item, boolean notify) { 108 super.add(item, notify); 109 } 110 111 /** 112 * Returns the x-value for the specified item. 113 * 114 * @param index the item index. 115 * 116 * @return The x-value (never {@code null}). 117 */ 118 public Number getX(int index) { 119 XIntervalDataItem item = (XIntervalDataItem) getDataItem(index); 120 return item.getX(); 121 } 122 123 /** 124 * Returns the lower bound of the x-interval for the specified item. 125 * 126 * @param index the item index. 127 * 128 * @return The lower bound of the x-interval. 129 * 130 * @since 1.0.10 131 */ 132 public double getXLowValue(int index) { 133 XIntervalDataItem item = (XIntervalDataItem) getDataItem(index); 134 return item.getXLowValue(); 135 } 136 137 /** 138 * Returns the upper bound of the x-interval for the specified item. 139 * 140 * @param index the item index. 141 * 142 * @return The upper bound of the x-interval. 143 * 144 * @since 1.0.10 145 */ 146 public double getXHighValue(int index) { 147 XIntervalDataItem item = (XIntervalDataItem) getDataItem(index); 148 return item.getXHighValue(); 149 } 150 151 /** 152 * Returns the y-value for the specified item. 153 * 154 * @param index the item index. 155 * 156 * @return The y-value. 157 */ 158 public double getYValue(int index) { 159 XIntervalDataItem item = (XIntervalDataItem) getDataItem(index); 160 return item.getYValue(); 161 } 162 163 /** 164 * Returns the data item at the specified index. 165 * 166 * @param index the item index. 167 * 168 * @return The data item. 169 */ 170 @Override 171 public ComparableObjectItem getDataItem(int index) { 172 return super.getDataItem(index); 173 } 174 175}