1 47 48 package org.jfree.data.xy; 49 50 import java.util.Date ; 51 52 55 public class DefaultHighLowDataset extends AbstractXYDataset 56 implements OHLCDataset { 57 58 59 private Comparable seriesKey; 60 61 62 private Date [] date; 63 64 65 private Number [] high; 66 67 68 private Number [] low; 69 70 71 private Number [] open; 72 73 74 private Number [] close; 75 76 77 private Number [] volume; 78 79 93 public DefaultHighLowDataset(Comparable seriesKey, 94 Date [] date, 95 double[] high, final double[] low, 96 double[] open, final double[] close, 97 double[] volume) { 98 99 this.seriesKey = seriesKey; 100 this.date = date; 101 this.high = createNumberArray(high); 102 this.low = createNumberArray(low); 103 this.open = createNumberArray(open); 104 this.close = createNumberArray(close); 105 this.volume = createNumberArray(volume); 106 107 } 108 109 116 public Comparable getSeriesKey(int i) { 117 return this.seriesKey; 118 } 119 120 130 public Number getX(int series, int item) { 131 return new Long (this.date[item].getTime()); 132 } 133 134 144 public Date getXDate(int series, int item) { 145 return this.date[item]; 146 } 147 148 159 public Number getY(int series, int item) { 160 return getClose(series, item); 161 } 162 163 171 public Number getHigh(int series, int item) { 172 return this.high[item]; 173 } 174 175 184 public double getHighValue(int series, int item) { 185 double result = Double.NaN; 186 Number high = getHigh(series, item); 187 if (high != null) { 188 result = high.doubleValue(); 189 } 190 return result; 191 } 192 193 201 public Number getLow(int series, int item) { 202 return this.low[item]; 203 } 204 205 214 public double getLowValue(int series, int item) { 215 double result = Double.NaN; 216 Number low = getLow(series, item); 217 if (low != null) { 218 result = low.doubleValue(); 219 } 220 return result; 221 } 222 223 231 public Number getOpen(int series, int item) { 232 return this.open[item]; 233 } 234 235 244 public double getOpenValue(int series, int item) { 245 double result = Double.NaN; 246 Number open = getOpen(series, item); 247 if (open != null) { 248 result = open.doubleValue(); 249 } 250 return result; 251 } 252 253 261 public Number getClose(int series, int item) { 262 return this.close[item]; 263 } 264 265 274 public double getCloseValue(int series, int item) { 275 double result = Double.NaN; 276 Number close = getClose(series, item); 277 if (close != null) { 278 result = close.doubleValue(); 279 } 280 return result; 281 } 282 283 291 public Number getVolume(int series, int item) { 292 return this.volume[item]; 293 } 294 295 304 public double getVolumeValue(int series, int item) { 305 double result = Double.NaN; 306 Number volume = getVolume(series, item); 307 if (volume != null) { 308 result = volume.doubleValue(); 309 } 310 return result; 311 } 312 313 320 public int getSeriesCount() { 321 return 1; 322 } 323 324 331 public int getItemCount(int series) { 332 return this.date.length; 333 } 334 335 342 public static Number [] createNumberArray(double[] data) { 343 Number [] result = new Number [data.length]; 344 for (int i = 0; i < data.length; i++) { 345 result[i] = new Double (data[i]); 346 } 347 return result; 348 } 349 350 } 351 | Popular Tags |