001 /* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2005, 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 * OHLCDataItem.java 029 * ----------------- 030 * (C) Copyright 2003-2005, by Object Refinery Limited. 031 * 032 * Original Author: David Gilbert (for Object Refinery Limited); 033 * Contributor(s): -; 034 * 035 * $Id: OHLCDataItem.java,v 1.6.2.1 2005/10/25 21:36:51 mungady Exp $ 036 * 037 * Changes 038 * ------- 039 * 03-Dec-2003 : Version 1 (DG); 040 * 29-Apr-2005 : Added equals() method (DG); 041 * 042 */ 043 044 package org.jfree.data.xy; 045 046 import java.io.Serializable; 047 import java.util.Date; 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 */ 055 public 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, 089 double open, 090 double high, 091 double low, 092 double close, 093 double volume) { 094 if (date == null) { 095 throw new IllegalArgumentException("Null 'date' argument."); 096 } 097 this.date = date; 098 this.open = new Double(open); 099 this.high = new Double(high); 100 this.low = new Double(low); 101 this.close = new Double(close); 102 this.volume = new Double(volume); 103 } 104 105 /** 106 * Returns the date that the data item relates to. 107 * 108 * @return The date (never <code>null</code>). 109 */ 110 public Date getDate() { 111 return this.date; 112 } 113 114 /** 115 * Returns the open value. 116 * 117 * @return The open value. 118 */ 119 public Number getOpen() { 120 return this.open; 121 } 122 123 /** 124 * Returns the high value. 125 * 126 * @return The high value. 127 */ 128 public Number getHigh() { 129 return this.high; 130 } 131 132 /** 133 * Returns the low value. 134 * 135 * @return The low value. 136 */ 137 public Number getLow() { 138 return this.low; 139 } 140 141 /** 142 * Returns the close value. 143 * 144 * @return The close value. 145 */ 146 public Number getClose() { 147 return this.close; 148 } 149 150 /** 151 * Returns the volume. 152 * 153 * @return The volume. 154 */ 155 public Number getVolume() { 156 return this.volume; 157 } 158 159 /** 160 * Checks this instance for equality with an arbitrary object. 161 * 162 * @param obj the object (<code>null</code> permitted). 163 * 164 * @return A boolean. 165 */ 166 public boolean equals(Object obj) { 167 if (obj == this) { 168 return true; 169 } 170 if (!(obj instanceof OHLCDataItem)) { 171 return false; 172 } 173 OHLCDataItem that = (OHLCDataItem) obj; 174 if (!this.date.equals(that.date)) { 175 return false; 176 } 177 if (!this.high.equals(that.high)) { 178 return false; 179 } 180 if (!this.low.equals(that.low)) { 181 return false; 182 } 183 if (!this.open.equals(that.open)) { 184 return false; 185 } 186 if (!this.close.equals(that.close)) { 187 return false; 188 } 189 return true; 190 } 191 192 /** 193 * Compares this object with the specified object for order. Returns a 194 * negative integer, zero, or a positive integer as this object is less 195 * than, equal to, or greater than the specified object. 196 * 197 * @param object the object to compare to. 198 * 199 * @return A negative integer, zero, or a positive integer as this object 200 * is less than, equal to, or greater than the specified object. 201 */ 202 public int compareTo(Object object) { 203 if (object instanceof OHLCDataItem) { 204 OHLCDataItem item = (OHLCDataItem) object; 205 return this.date.compareTo(item.date); 206 } 207 else { 208 throw new ClassCastException("OHLCDataItem.compareTo()."); 209 } 210 } 211 212 }