001/* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2011, 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 * [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 * OHLCSeries.java 029 * --------------- 030 * (C) Copyright 2006-2009, by Object Refinery Limited. 031 * 032 * Original Author: David Gilbert (for Object Refinery Limited); 033 * Contributor(s): -; 034 * 035 * Changes 036 * ------- 037 * 04-Dec-2006 : Version 1 (DG); 038 * 17-Jun-2009 : Added remove(int) method (DG); 039 * 040 */ 041 042package org.jfree.data.time.ohlc; 043 044import org.jfree.data.ComparableObjectItem; 045import org.jfree.data.ComparableObjectSeries; 046import org.jfree.data.time.RegularTimePeriod; 047 048/** 049 * A list of ({@link RegularTimePeriod}, open, high, low, close) data items. 050 * 051 * @since 1.0.4 052 * 053 * @see OHLCSeriesCollection 054 */ 055public class OHLCSeries extends ComparableObjectSeries { 056 057 /** 058 * Creates a new empty series. By default, items added to the series will 059 * be sorted into ascending order by period, and duplicate periods will 060 * not be allowed. 061 * 062 * @param key the series key (<code>null</code> not permitted). 063 */ 064 public OHLCSeries(Comparable key) { 065 super(key, true, false); 066 } 067 068 /** 069 * Returns the time period for the specified item. 070 * 071 * @param index the item index. 072 * 073 * @return The time period. 074 */ 075 public RegularTimePeriod getPeriod(int index) { 076 OHLCItem item = (OHLCItem) getDataItem(index); 077 return item.getPeriod(); 078 } 079 080 /** 081 * Returns the data item at the specified index. 082 * 083 * @param index the item index. 084 * 085 * @return The data item. 086 */ 087 public ComparableObjectItem getDataItem(int index) { 088 return super.getDataItem(index); 089 } 090 091 /** 092 * Adds a data item to the series. 093 * 094 * @param period the period. 095 * @param open the open-value. 096 * @param high the high-value. 097 * @param low the low-value. 098 * @param close the close-value. 099 */ 100 public void add(RegularTimePeriod period, double open, double high, 101 double low, double close) { 102 if (getItemCount() > 0) { 103 OHLCItem item0 = (OHLCItem) this.getDataItem(0); 104 if (!period.getClass().equals(item0.getPeriod().getClass())) { 105 throw new IllegalArgumentException( 106 "Can't mix RegularTimePeriod class types."); 107 } 108 } 109 super.add(new OHLCItem(period, open, high, low, close), true); 110 } 111 112 /** 113 * Removes the item with the specified index. 114 * 115 * @param index the item index. 116 * 117 * @since 1.0.14 118 */ 119 public ComparableObjectItem remove(int index) { 120 return super.remove(index); 121 } 122 123}