1 46 47 package org.jfree.data.xy; 48 49 import java.util.Arrays ; 50 import java.util.Date ; 51 52 56 public class DefaultOHLCDataset extends AbstractXYDataset 57 implements OHLCDataset { 58 59 60 private Comparable key; 61 62 63 private OHLCDataItem[] data; 64 65 71 public DefaultOHLCDataset(Comparable key, OHLCDataItem[] data) { 72 this.key = key; 73 this.data = data; 74 } 75 76 83 public Comparable getSeriesKey(int series) { 84 return this.key; 85 } 86 87 95 public Number getX(int series, int item) { 96 return new Long (this.data[item].getDate().getTime()); 97 } 98 99 107 public Date getXDate(int series, int item) { 108 return this.data[item].getDate(); 109 } 110 111 119 public Number getY(int series, int item) { 120 return getClose(series, item); 121 } 122 123 131 public Number getHigh(int series, int item) { 132 return this.data[item].getHigh(); 133 } 134 135 144 public double getHighValue(int series, int item) { 145 double result = Double.NaN; 146 Number high = getHigh(series, item); 147 if (high != null) { 148 result = high.doubleValue(); 149 } 150 return result; 151 } 152 153 161 public Number getLow(int series, int item) { 162 return this.data[item].getLow(); 163 } 164 165 174 public double getLowValue(int series, int item) { 175 double result = Double.NaN; 176 Number low = getLow(series, item); 177 if (low != null) { 178 result = low.doubleValue(); 179 } 180 return result; 181 } 182 183 191 public Number getOpen(int series, int item) { 192 return this.data[item].getOpen(); 193 } 194 195 204 public double getOpenValue(int series, int item) { 205 double result = Double.NaN; 206 Number open = getOpen(series, item); 207 if (open != null) { 208 result = open.doubleValue(); 209 } 210 return result; 211 } 212 213 221 public Number getClose(int series, int item) { 222 return this.data[item].getClose(); 223 } 224 225 234 public double getCloseValue(int series, int item) { 235 double result = Double.NaN; 236 Number close = getClose(series, item); 237 if (close != null) { 238 result = close.doubleValue(); 239 } 240 return result; 241 } 242 243 251 public Number getVolume(int series, int item) { 252 return this.data[item].getVolume(); 253 } 254 255 264 public double getVolumeValue(int series, int item) { 265 double result = Double.NaN; 266 Number volume = getVolume(series, item); 267 if (volume != null) { 268 result = volume.doubleValue(); 269 } 270 return result; 271 } 272 273 278 public int getSeriesCount() { 279 return 1; 280 } 281 282 289 public int getItemCount(int series) { 290 return this.data.length; 291 } 292 293 296 public void sortDataByDate() { 297 Arrays.sort(this.data); 298 } 299 300 307 public boolean equals(Object obj) { 308 if (this == obj) { 309 return true; 310 } 311 if (!(obj instanceof DefaultOHLCDataset)) { 312 return false; 313 } 314 DefaultOHLCDataset that = (DefaultOHLCDataset) obj; 315 if (!this.key.equals(that.key)) { 316 return false; 317 } 318 if (!Arrays.equals(this.data, that.data)) { 319 return false; 320 } 321 return true; 322 } 323 324 } 325 | Popular Tags |