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 * OHLCItem.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 * 04-Dec-2006 : Version 1 (DG);
038 *
039 */
040
041 package org.jfree.data.time.ohlc;
042
043 import org.jfree.data.ComparableObjectItem;
044 import org.jfree.data.time.RegularTimePeriod;
045
046 /**
047 * An item representing data in the form (period, open, high, low, close).
048 *
049 * @since 1.0.4
050 */
051 public class OHLCItem extends ComparableObjectItem {
052
053 /**
054 * Creates a new instance of <code>OHLCItem</code>.
055 *
056 * @param period the time period.
057 * @param open the open-value.
058 * @param high the high-value.
059 * @param low the low-value.
060 * @param close the close-value.
061 */
062 public OHLCItem(RegularTimePeriod period, double open, double high,
063 double low, double close) {
064 super(period, new OHLC(open, high, low, close));
065 }
066
067 /**
068 * Returns the period.
069 *
070 * @return The period (never <code>null</code>).
071 */
072 public RegularTimePeriod getPeriod() {
073 return (RegularTimePeriod) getComparable();
074 }
075
076 /**
077 * Returns the y-value.
078 *
079 * @return The y-value.
080 */
081 public double getYValue() {
082 return getCloseValue();
083 }
084
085 /**
086 * Returns the open value.
087 *
088 * @return The open value.
089 */
090 public double getOpenValue() {
091 OHLC ohlc = (OHLC) getObject();
092 if (ohlc != null) {
093 return ohlc.getOpen();
094 }
095 else {
096 return Double.NaN;
097 }
098 }
099
100 /**
101 * Returns the high value.
102 *
103 * @return The high value.
104 */
105 public double getHighValue() {
106 OHLC ohlc = (OHLC) getObject();
107 if (ohlc != null) {
108 return ohlc.getHigh();
109 }
110 else {
111 return Double.NaN;
112 }
113 }
114
115 /**
116 * Returns the low value.
117 *
118 * @return The low value.
119 */
120 public double getLowValue() {
121 OHLC ohlc = (OHLC) getObject();
122 if (ohlc != null) {
123 return ohlc.getLow();
124 }
125 else {
126 return Double.NaN;
127 }
128 }
129
130 /**
131 * Returns the close value.
132 *
133 * @return The close value.
134 */
135 public double getCloseValue() {
136 OHLC ohlc = (OHLC) getObject();
137 if (ohlc != null) {
138 return ohlc.getClose();
139 }
140 else {
141 return Double.NaN;
142 }
143 }
144
145 }