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