Source for org.jfree.data.time.ohlc.OHLCItem

   1: /* ===========================================================
   2:  * JFreeChart : a free chart library for the Java(tm) platform
   3:  * ===========================================================
   4:  *
   5:  * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors.
   6:  *
   7:  * Project Info:  http://www.jfree.org/jfreechart/index.html
   8:  *
   9:  * This library is free software; you can redistribute it and/or modify it 
  10:  * under the terms of the GNU Lesser General Public License as published by 
  11:  * the Free Software Foundation; either version 2.1 of the License, or 
  12:  * (at your option) any later version.
  13:  *
  14:  * This library is distributed in the hope that it will be useful, but 
  15:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
  16:  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
  17:  * License for more details.
  18:  *
  19:  * You should have received a copy of the GNU Lesser General Public
  20:  * License along with this library; if not, write to the Free Software
  21:  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
  22:  * USA.  
  23:  *
  24:  * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
  25:  * in the United States and other countries.]
  26:  *
  27:  * -------------
  28:  * OHLCItem.java
  29:  * -------------
  30:  * (C) Copyright 2006, by Object Refinery Limited.
  31:  *
  32:  * Original Author:  David Gilbert (for Object Refinery Limited);
  33:  * Contributor(s):   -;
  34:  *
  35:  * $Id: OHLCItem.java,v 1.1.2.1 2006/12/04 17:08:36 mungady Exp $
  36:  *
  37:  * Changes
  38:  * -------
  39:  * 04-Dec-2006 : Version 1 (DG);
  40:  *
  41:  */
  42: 
  43: package org.jfree.data.time.ohlc;
  44: 
  45: import org.jfree.data.ComparableObjectItem;
  46: import org.jfree.data.time.RegularTimePeriod;
  47: 
  48: /**
  49:  * An item representing data in the form (period, open, high, low, close).
  50:  *
  51:  * @since 1.0.4
  52:  */
  53: public class OHLCItem extends ComparableObjectItem {
  54: 
  55:     /** 
  56:      * Creates a new instance of <code>OHLCItem</code>.
  57:      *
  58:      * @param period  the time period.
  59:      * @param open  the open-value.
  60:      * @param high  the high-value.
  61:      * @param low  the low-value.
  62:      * @param close  the close-value.
  63:      */
  64:     public OHLCItem(RegularTimePeriod period, double open, double high, 
  65:             double low, double close) {
  66:         super(period, new OHLC(open, high, low, close));
  67:     }
  68:     
  69:     /**
  70:      * Returns the period.
  71:      *
  72:      * @return The period (never <code>null</code>).
  73:      */
  74:     public RegularTimePeriod getPeriod() {
  75:         return (RegularTimePeriod) getComparable();
  76:     }
  77:     
  78:     /**
  79:      * Returns the y-value.
  80:      *
  81:      * @return The y-value.
  82:      */
  83:     public double getYValue() {
  84:         return getCloseValue();
  85:     }
  86:     
  87:     /**
  88:      * Returns the open value.
  89:      *
  90:      * @return The open value.
  91:      */
  92:     public double getOpenValue() {
  93:         OHLC ohlc = (OHLC) getObject();
  94:         if (ohlc != null) {
  95:             return ohlc.getOpen();
  96:         }
  97:         else {
  98:             return Double.NaN;
  99:         }
 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: }