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 * OHLCDataItem.java 029 * ----------------- 030 * (C) Copyright 2003-2013, by Object Refinery Limited. 031 * 032 * Original Author: David Gilbert (for Object Refinery Limited); 033 * Contributor(s): -; 034 * 035 * Changes 036 * ------- 037 * 03-Dec-2003 : Version 1 (DG); 038 * 29-Apr-2005 : Added equals() method (DG); 039 * 02-Jul-2013 : Use ParamChecks (DG); 040 * 041 */ 042 043package org.jfree.data.xy; 044 045import java.io.Serializable; 046import java.util.Date; 047import org.jfree.chart.util.ParamChecks; 048 049/** 050 * Represents a single (open-high-low-close) data item in 051 * an {@link DefaultOHLCDataset}. This data item is commonly used 052 * to summarise the trading activity of a financial commodity for 053 * a fixed period (most often one day). 054 */ 055public class OHLCDataItem implements Comparable, Serializable { 056 057 /** For serialization. */ 058 private static final long serialVersionUID = 7753817154401169901L; 059 060 /** The date. */ 061 private Date date; 062 063 /** The open value. */ 064 private Number open; 065 066 /** The high value. */ 067 private Number high; 068 069 /** The low value. */ 070 private Number low; 071 072 /** The close value. */ 073 private Number close; 074 075 /** The trading volume (number of shares, contracts or whatever). */ 076 private Number volume; 077 078 /** 079 * Creates a new item. 080 * 081 * @param date the date (<code>null</code> not permitted). 082 * @param open the open value. 083 * @param high the high value. 084 * @param low the low value. 085 * @param close the close value. 086 * @param volume the volume. 087 */ 088 public OHLCDataItem(Date date, double open, double high, double low, 089 double close, double volume) { 090 ParamChecks.nullNotPermitted(date, "date"); 091 this.date = date; 092 this.open = new Double(open); 093 this.high = new Double(high); 094 this.low = new Double(low); 095 this.close = new Double(close); 096 this.volume = new Double(volume); 097 } 098 099 /** 100 * Returns the date that the data item relates to. 101 * 102 * @return The date (never <code>null</code>). 103 */ 104 public Date getDate() { 105 return this.date; 106 } 107 108 /** 109 * Returns the open value. 110 * 111 * @return The open value (never <code>null</code>). 112 */ 113 public Number getOpen() { 114 return this.open; 115 } 116 117 /** 118 * Returns the high value. 119 * 120 * @return The high value (never <code>null</code>). 121 */ 122 public Number getHigh() { 123 return this.high; 124 } 125 126 /** 127 * Returns the low value. 128 * 129 * @return The low value (never <code>null</code>). 130 */ 131 public Number getLow() { 132 return this.low; 133 } 134 135 /** 136 * Returns the close value. 137 * 138 * @return The close value (never <code>null</code>). 139 */ 140 public Number getClose() { 141 return this.close; 142 } 143 144 /** 145 * Returns the volume. 146 * 147 * @return The volume (never <code>null</code>). 148 */ 149 public Number getVolume() { 150 return this.volume; 151 } 152 153 /** 154 * Checks this instance for equality with an arbitrary object. 155 * 156 * @param obj the object (<code>null</code> permitted). 157 * 158 * @return A boolean. 159 */ 160 @Override 161 public boolean equals(Object obj) { 162 if (obj == this) { 163 return true; 164 } 165 if (!(obj instanceof OHLCDataItem)) { 166 return false; 167 } 168 OHLCDataItem that = (OHLCDataItem) obj; 169 if (!this.date.equals(that.date)) { 170 return false; 171 } 172 if (!this.high.equals(that.high)) { 173 return false; 174 } 175 if (!this.low.equals(that.low)) { 176 return false; 177 } 178 if (!this.open.equals(that.open)) { 179 return false; 180 } 181 if (!this.close.equals(that.close)) { 182 return false; 183 } 184 return true; 185 } 186 187 /** 188 * Compares this object with the specified object for order. Returns a 189 * negative integer, zero, or a positive integer as this object is less 190 * than, equal to, or greater than the specified object. 191 * 192 * @param object the object to compare to. 193 * 194 * @return A negative integer, zero, or a positive integer as this object 195 * is less than, equal to, or greater than the specified object. 196 */ 197 @Override 198 public int compareTo(Object object) { 199 if (object instanceof OHLCDataItem) { 200 OHLCDataItem item = (OHLCDataItem) object; 201 return this.date.compareTo(item.date); 202 } 203 else { 204 throw new ClassCastException("OHLCDataItem.compareTo()."); 205 } 206 } 207 208}