1 46 47 package org.jfree.data.xy; 48 49 import java.io.Serializable ; 50 51 import org.jfree.data.general.Series; 52 53 59 public class MatrixSeries extends Series implements Serializable { 60 61 62 private static final long serialVersionUID = 7934188527308315704L; 63 64 65 protected double[][] data; 66 67 77 public MatrixSeries(String name, int rows, int columns) { 78 super(name); 79 this.data = new double[rows][columns]; 80 zeroAll(); 81 } 82 83 88 public int getColumnsCount() { 89 return this.data[0].length; 90 } 91 92 93 100 public Number getItem(int itemIndex) { 101 int i = getItemRow(itemIndex); 102 int j = getItemColumn(itemIndex); 103 104 Number n = new Double (get(i, j)); 105 106 return n; 107 } 108 109 110 117 public int getItemColumn(int itemIndex) { 118 return itemIndex % getColumnsCount(); 120 } 121 122 123 128 public int getItemCount() { 129 return getRowCount() * getColumnsCount(); 130 } 131 132 133 140 public int getItemRow(int itemIndex) { 141 return itemIndex / getColumnsCount(); 143 } 144 145 146 151 public int getRowCount() { 152 return this.data.length; 153 } 154 155 156 164 public double get(int i, int j) { 165 return this.data[i][j]; 166 } 167 168 169 176 public void update(int i, int j, double mij) { 177 this.data[i][j] = mij; 178 fireSeriesChanged(); 179 } 180 181 182 187 public void zeroAll() { 188 int rows = getRowCount(); 189 int columns = getColumnsCount(); 190 191 for (int row = 0; row < rows; row++) { 192 for (int column = 0; column < columns; column++) { 193 this.data[row][column] = 0.0; 194 } 195 } 196 fireSeriesChanged(); 197 } 198 199 206 public boolean equals(Object obj) { 207 if (obj == this) { 208 return true; 209 } 210 if (obj instanceof MatrixSeries && super.equals(obj)) { 211 MatrixSeries m = (MatrixSeries) obj; 212 if (!(getRowCount() == m.getRowCount())) { 213 return false; 214 } 215 if (!(getColumnsCount() == m.getColumnsCount())) { 216 return false; 217 } 218 return true; 219 } 220 return false; 221 } 222 223 } 224 | Popular Tags |