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, double open, double high,
089: double low, double close, double volume) {
090: if (date == null) {
091: throw new IllegalArgumentException("Null 'date' argument.");
092: }
093: this .date = date;
094: this .open = new Double(open);
095: this .high = new Double(high);
096: this .low = new Double(low);
097: this .close = new Double(close);
098: this .volume = new Double(volume);
099: }
100:
101: /**
102: * Returns the date that the data item relates to.
103: *
104: * @return The date (never <code>null</code>).
105: */
106: public Date getDate() {
107: return this .date;
108: }
109:
110: /**
111: * Returns the open value.
112: *
113: * @return The open value.
114: */
115: public Number getOpen() {
116: return this .open;
117: }
118:
119: /**
120: * Returns the high value.
121: *
122: * @return The high value.
123: */
124: public Number getHigh() {
125: return this .high;
126: }
127:
128: /**
129: * Returns the low value.
130: *
131: * @return The low value.
132: */
133: public Number getLow() {
134: return this .low;
135: }
136:
137: /**
138: * Returns the close value.
139: *
140: * @return The close value.
141: */
142: public Number getClose() {
143: return this .close;
144: }
145:
146: /**
147: * Returns the volume.
148: *
149: * @return The volume.
150: */
151: public Number getVolume() {
152: return this .volume;
153: }
154:
155: /**
156: * Checks this instance for equality with an arbitrary object.
157: *
158: * @param obj the object (<code>null</code> permitted).
159: *
160: * @return A boolean.
161: */
162: public boolean equals(Object obj) {
163: if (obj == this ) {
164: return true;
165: }
166: if (!(obj instanceof OHLCDataItem)) {
167: return false;
168: }
169: OHLCDataItem that = (OHLCDataItem) obj;
170: if (!this .date.equals(that.date)) {
171: return false;
172: }
173: if (!this .high.equals(that.high)) {
174: return false;
175: }
176: if (!this .low.equals(that.low)) {
177: return false;
178: }
179: if (!this .open.equals(that.open)) {
180: return false;
181: }
182: if (!this .close.equals(that.close)) {
183: return false;
184: }
185: return true;
186: }
187:
188: /**
189: * Compares this object with the specified object for order. Returns a
190: * negative integer, zero, or a positive integer as this object is less
191: * than, equal to, or greater than the specified object.
192: *
193: * @param object the object to compare to.
194: *
195: * @return A negative integer, zero, or a positive integer as this object
196: * is less than, equal to, or greater than the specified object.
197: */
198: public int compareTo(Object object) {
199: if (object instanceof OHLCDataItem) {
200: OHLCDataItem item = (OHLCDataItem) object;
201: return this .date.compareTo(item.date);
202: } else {
203: throw new ClassCastException("OHLCDataItem.compareTo().");
204: }
205: }
206:
207: }
|