1 37 38 package org.jfree.data; 39 40 import java.util.Arrays ; 41 import java.util.Collections ; 42 import java.util.Date ; 43 import java.util.List ; 44 45 50 public class DefaultWindDataset extends AbstractSeriesDataset implements WindDataset { 51 52 53 private List seriesNames; 54 55 56 private List allSeriesData; 57 58 61 public DefaultWindDataset() { 62 seriesNames = new java.util.ArrayList (); 63 allSeriesData = new java.util.ArrayList (); 64 } 65 66 71 public DefaultWindDataset(Object [][][] data) { 72 this(seriesNameListFromDataArray(data), data); 73 } 74 75 81 public DefaultWindDataset(String [] seriesNames, Object [][][] data) { 82 this(Arrays.asList(seriesNames), data); 83 } 84 85 91 public DefaultWindDataset(List seriesNames, Object [][][] data) { 92 93 this.seriesNames = seriesNames; 94 95 int seriesCount = data.length; 96 97 allSeriesData = new java.util.ArrayList (seriesCount); 98 99 for (int seriesIndex = 0; seriesIndex < seriesCount; seriesIndex++) { 100 List oneSeriesData = new java.util.ArrayList (); 101 int maxItemCount = data[seriesIndex].length; 102 for (int itemIndex = 0; itemIndex < maxItemCount; itemIndex++) { 103 Object xObject = data[seriesIndex][itemIndex][0]; 104 if (xObject != null) { 105 Number xNumber = null; 106 if (xObject instanceof Number ) { 107 xNumber = (Number ) xObject; 108 } 109 else { 110 if (xObject instanceof Date ) { 111 Date xDate = (Date ) xObject; 112 xNumber = new Long (xDate.getTime()); 113 } 114 else { 115 xNumber = new Integer (0); 116 } 117 } 118 Number windDir = (Number ) data[seriesIndex][itemIndex][1]; 119 Number windForce = (Number ) data[seriesIndex][itemIndex][2]; 120 oneSeriesData.add(new WindDataItem(xNumber, windDir, windForce)); 121 } 122 } 123 Collections.sort(oneSeriesData); 124 allSeriesData.add(seriesIndex, oneSeriesData); 125 } 126 127 } 128 129 133 public int getSeriesCount() { 134 return allSeriesData.size(); 135 } 136 137 142 public int getItemCount(int series) { 143 List oneSeriesData = (List ) allSeriesData.get(series); 144 return oneSeriesData.size(); 145 } 146 147 152 public String getSeriesName(int series) { 153 return seriesNames.get(series).toString(); 154 } 155 156 165 public Number getXValue(int series, int item) { 166 List oneSeriesData = (List ) allSeriesData.get(series); 167 WindDataItem windItem = (WindDataItem) oneSeriesData.get(item); 168 return windItem.getX(); 169 } 170 171 180 public Number getYValue(int series, int item) { 181 return getWindForce(series, item); 182 } 183 184 191 public Number getWindDirection(int series, int item) { 192 List oneSeriesData = (List ) allSeriesData.get(series); 193 WindDataItem windItem = (WindDataItem) oneSeriesData.get(item); 194 return windItem.getWindDirection(); 195 } 196 197 204 public Number getWindForce(int series, int item) { 205 List oneSeriesData = (List ) allSeriesData.get(series); 206 WindDataItem windItem = (WindDataItem) oneSeriesData.get(item); 207 return windItem.getWindForce(); 208 } 209 210 216 public static List seriesNameListFromDataArray(Object [][] data) { 217 218 int seriesCount = data.length; 219 List seriesNameList = new java.util.ArrayList (seriesCount); 220 for (int i = 0; i < seriesCount; i++) { 221 seriesNameList.add("Series " + (i + 1)); 222 } 223 return seriesNameList; 224 225 } 226 227 } 228 229 234 class WindDataItem implements Comparable { 235 236 237 private Number x; 238 239 240 private Number windDir; 241 242 243 private Number windForce; 244 245 252 public WindDataItem(Number x, Number windDir, Number windForce) { 253 this.x = x; 254 this.windDir = windDir; 255 this.windForce = windForce; 256 } 257 258 263 public Number getX() { 264 return this.x; 265 } 266 267 272 public Number getWindDirection() { 273 return this.windDir; 274 } 275 276 281 public Number getWindForce() { 282 return this.windForce; 283 } 284 285 292 public int compareTo(Object object) { 293 if (object instanceof WindDataItem) { 294 WindDataItem item = (WindDataItem) object; 295 if (this.x.doubleValue() > item.x.doubleValue()) { 296 return 1; 297 } 298 else if (this.x.equals(item.x)) { 299 return 0; 300 } 301 else { 302 return -1; 303 } 304 } 305 else { 306 throw new ClassCastException ("WindDataItem.compareTo(error)"); 307 } 308 } 309 310 } 311 | Popular Tags |