1 37 package org.jfree.data; 38 39 import java.io.Serializable ; 40 41 47 public class MatrixSeries extends Series implements Serializable { 48 49 50 protected double[][] m_data; 51 52 63 public MatrixSeries(String name, int rows, int columns) { 64 super(name); 65 m_data = new double[rows][columns]; 66 zeroAll(); 67 } 68 69 74 public int getColumnsCount() { 75 return m_data[0].length; 76 } 77 78 79 86 public Number getItem(int itemIndex) { 87 int i = getItemRow(itemIndex); 88 int j = getItemColumn(itemIndex); 89 90 Number n = new Double (get(i, j)); 91 92 return n; 93 } 94 95 96 103 public int getItemColumn(int itemIndex) { 104 106 return itemIndex % getRowCount(); 107 } 108 109 110 115 public int getItemCount() { 116 return getRowCount() * getColumnsCount(); 117 } 118 119 120 127 public int getItemRow(int itemIndex) { 128 130 return itemIndex / getRowCount(); 131 } 132 133 134 139 public int getRowCount() { 140 return m_data.length; 141 } 142 143 144 152 public double get(int i, int j) { 153 return m_data[i][j]; 154 } 155 156 157 164 public void update(int i, int j, double mij) { 165 m_data[i][j] = mij; 166 167 fireSeriesChanged(); 168 } 169 170 171 174 public void zeroAll() { 175 double[][] data = m_data; 176 int rows = getRowCount(); 177 int columns = getColumnsCount(); 178 179 for (int i = 0; i < rows; i++) { 180 for (int j = 0; j < columns; j++) { 181 data[i][j] = 0.0; 182 } 183 } 184 185 fireSeriesChanged(); 186 } 187 } 188 | Popular Tags |