1. /* ===========================================================
  2. * JFreeChart : a free chart library for the Java(tm) platform
  3. * ===========================================================
  4. *
  5. * (C) Copyright 2000-2004, 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 under the terms
  10. * of the GNU Lesser General Public License as published by the Free Software Foundation;
  11. * either version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  14. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. * See the GNU Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License along with this
  18. * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  19. * Boston, MA 02111-1307, USA.
  20. *
  21. * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  22. * in the United States and other countries.]
  23. *
  24. * -----------------
  25. * OHLCDataItem.java
  26. * -----------------
  27. * (C) Copyright 2003, 2004, by Object Refinery Limited.
  28. *
  29. * Original Author: David Gilbert (for Object Refinery Limited);
  30. * Contributor(s): -;
  31. *
  32. * $Id: OHLCDataItem.java,v 1.3 2004/11/29 15:18:36 mungady Exp $
  33. *
  34. * Changes
  35. * -------
  36. * 03-Dec-2003 : Version 1 (DG);
  37. *
  38. */
  39. package org.jfree.data.xy;
  40. import java.util.Date;
  41. /**
  42. * Represents a single (open-high-low-close) data item in
  43. * an {@link DefaultOHLCDataset}. This data item is commonly used
  44. * to summarise the trading activity of a financial commodity for
  45. * a fixed period (most often one day).
  46. */
  47. public class OHLCDataItem implements Comparable {
  48. /** The date. */
  49. private Date date;
  50. /** The open value. */
  51. private Number open;
  52. /** The high value. */
  53. private Number high;
  54. /** The low value. */
  55. private Number low;
  56. /** The close value. */
  57. private Number close;
  58. /** The trading volume (number of shares, contracts or whatever). */
  59. private Number volume;
  60. /**
  61. * Creates a new item.
  62. *
  63. * @param date the date (<code>null</code> not permitted).
  64. * @param open the open value.
  65. * @param high the high value.
  66. * @param low the low value.
  67. * @param close the close value.
  68. * @param volume the volume.
  69. */
  70. public OHLCDataItem(Date date,
  71. double open,
  72. double high,
  73. double low,
  74. double close,
  75. double volume) {
  76. if (date == null) {
  77. throw new IllegalArgumentException("Null 'date' argument.");
  78. }
  79. this.date = date;
  80. this.open = new Double(open);
  81. this.high = new Double(high);
  82. this.low = new Double(low);
  83. this.close = new Double(close);
  84. this.volume = new Double(volume);
  85. }
  86. /**
  87. * Returns the date that the data item relates to.
  88. *
  89. * @return The date (never <code>null</code>).
  90. */
  91. public Date getDate() {
  92. return this.date;
  93. }
  94. /**
  95. * Returns the open value.
  96. *
  97. * @return The open value.
  98. */
  99. public Number getOpen() {
  100. return this.open;
  101. }
  102. /**
  103. * Returns the high value.
  104. *
  105. * @return The high value.
  106. */
  107. public Number getHigh() {
  108. return this.high;
  109. }
  110. /**
  111. * Returns the low value.
  112. *
  113. * @return The low value.
  114. */
  115. public Number getLow() {
  116. return this.low;
  117. }
  118. /**
  119. * Returns the close value.
  120. *
  121. * @return The close value.
  122. */
  123. public Number getClose() {
  124. return this.close;
  125. }
  126. /**
  127. * Returns the volume.
  128. *
  129. * @return The volume.
  130. */
  131. public Number getVolume() {
  132. return this.volume;
  133. }
  134. /**
  135. * Compares this object with the specified object for order. Returns a negative integer, zero,
  136. * or a positive integer as this object is less than, equal to, or greater than the specified
  137. * object.
  138. *
  139. * @param object the object to compare to.
  140. *
  141. * @return a negative integer, zero, or a positive integer as this object is less than, equal
  142. * to, or greater than the specified object.
  143. */
  144. public int compareTo(Object object) {
  145. if (object instanceof OHLCDataItem) {
  146. OHLCDataItem item = (OHLCDataItem) object;
  147. return this.date.compareTo(item.date);
  148. }
  149. else {
  150. throw new ClassCastException("OHLCDataItem.compareTo().");
  151. }
  152. }
  153. }