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