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