1:
40:
41: package ;
42:
43:
44: import ;
45: import ;
46: import ;
47: import ;
48:
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55:
56:
61: public class DefaultMultiValueCategoryDataset extends AbstractDataset
62: implements MultiValueCategoryDataset, RangeInfo, PublicCloneable {
63:
64:
67: protected KeyedObjects2D data;
68:
69:
72: private Number minimumRangeValue;
73:
74:
77: private Number maximumRangeValue;
78:
79:
82: private Range rangeBounds;
83:
84:
87: public DefaultMultiValueCategoryDataset() {
88: this.data = new KeyedObjects2D();
89: this.minimumRangeValue = null;
90: this.maximumRangeValue = null;
91: this.rangeBounds = new Range(0.0, 0.0);
92: }
93:
94:
103: public void add(List values, Comparable rowKey, Comparable columnKey) {
104:
105: if (values == null) {
106: throw new IllegalArgumentException("Null 'values' argument.");
107: }
108: if (rowKey == null) {
109: throw new IllegalArgumentException("Null 'rowKey' argument.");
110: }
111: if (columnKey == null) {
112: throw new IllegalArgumentException("Null 'columnKey' argument.");
113: }
114: List vlist = new ArrayList(values.size());
115: Iterator iterator = values.listIterator();
116: while (iterator.hasNext()) {
117: Object obj = iterator.next();
118: if (obj instanceof Number) {
119: Number n = (Number) obj;
120: double v = n.doubleValue();
121: if (!Double.isNaN(v)) {
122: vlist.add(n);
123: }
124: }
125: }
126: Collections.sort(vlist);
127: this.data.addObject(vlist, rowKey, columnKey);
128:
129: if (vlist.size() > 0) {
130: double maxval = Double.NEGATIVE_INFINITY;
131: double minval = Double.POSITIVE_INFINITY;
132: for (int i = 0; i < vlist.size(); i++) {
133: Number n = (Number) vlist.get(i);
134: double v = n.doubleValue();
135: minval = Math.min(minval, v);
136: maxval = Math.max(maxval, v);
137: }
138:
139:
140: if (this.maximumRangeValue == null) {
141: this.maximumRangeValue = new Double(maxval);
142: }
143: else if (maxval > this.maximumRangeValue.doubleValue()) {
144: this.maximumRangeValue = new Double(maxval);
145: }
146:
147: if (this.minimumRangeValue == null) {
148: this.minimumRangeValue = new Double(minval);
149: }
150: else if (minval < this.minimumRangeValue.doubleValue()) {
151: this.minimumRangeValue = new Double(minval);
152: }
153: this.rangeBounds = new Range(this.minimumRangeValue.doubleValue(),
154: this.maximumRangeValue.doubleValue());
155: }
156:
157: fireDatasetChanged();
158: }
159:
160:
169: public List getValues(int row, int column) {
170: List values = (List) this.data.getObject(row, column);
171: if (values != null) {
172: return Collections.unmodifiableList(values);
173: }
174: else {
175: return Collections.EMPTY_LIST;
176: }
177: }
178:
179:
188: public List getValues(Comparable rowKey, Comparable columnKey) {
189: return Collections.unmodifiableList((List) this.data.getObject(rowKey,
190: columnKey));
191: }
192:
193:
201: public Number getValue(Comparable row, Comparable column) {
202: List l = (List) this.data.getObject(row, column);
203: double average = 0.0d;
204: int count = 0;
205: if (l != null && l.size() > 0) {
206: for (int i = 0; i < l.size(); i++) {
207: Number n = (Number) l.get(i);
208: average += n.doubleValue();
209: count += 1;
210: }
211: if (count > 0) {
212: average = average / count;
213: }
214: }
215: if (count == 0) {
216: return null;
217: }
218: return new Double(average);
219: }
220:
221:
229: public Number getValue(int row, int column) {
230: List l = (List) this.data.getObject(row, column);
231: double average = 0.0d;
232: int count = 0;
233: if (l != null && l.size() > 0) {
234: for (int i = 0; i < l.size(); i++) {
235: Number n = (Number) l.get(i);
236: average += n.doubleValue();
237: count += 1;
238: }
239: if (count > 0) {
240: average = average / count;
241: }
242: }
243: if (count == 0) {
244: return null;
245: }
246: return new Double(average);
247: }
248:
249:
256: public int getColumnIndex(Comparable key) {
257: return this.data.getColumnIndex(key);
258: }
259:
260:
267: public Comparable getColumnKey(int column) {
268: return this.data.getColumnKey(column);
269: }
270:
271:
276: public List getColumnKeys() {
277: return this.data.getColumnKeys();
278: }
279:
280:
287: public int getRowIndex(Comparable key) {
288: return this.data.getRowIndex(key);
289: }
290:
291:
298: public Comparable getRowKey(int row) {
299: return this.data.getRowKey(row);
300: }
301:
302:
307: public List getRowKeys() {
308: return this.data.getRowKeys();
309: }
310:
311:
316: public int getRowCount() {
317: return this.data.getRowCount();
318: }
319:
320:
325: public int getColumnCount() {
326: return this.data.getColumnCount();
327: }
328:
329:
337: public double getRangeLowerBound(boolean includeInterval) {
338: double result = Double.NaN;
339: if (this.minimumRangeValue != null) {
340: result = this.minimumRangeValue.doubleValue();
341: }
342: return result;
343: }
344:
345:
353: public double getRangeUpperBound(boolean includeInterval) {
354: double result = Double.NaN;
355: if (this.maximumRangeValue != null) {
356: result = this.maximumRangeValue.doubleValue();
357: }
358: return result;
359: }
360:
361:
368: public Range getRangeBounds(boolean includeInterval) {
369: return this.rangeBounds;
370: }
371:
372:
379: public boolean equals(Object obj) {
380: if (obj == this) {
381: return true;
382: }
383: if (!(obj instanceof DefaultMultiValueCategoryDataset)) {
384: return false;
385: }
386: DefaultMultiValueCategoryDataset that
387: = (DefaultMultiValueCategoryDataset) obj;
388: return this.data.equals(that.data);
389: }
390:
391:
398: public Object clone() throws CloneNotSupportedException {
399: DefaultMultiValueCategoryDataset clone
400: = (DefaultMultiValueCategoryDataset) super.clone();
401: clone.data = (KeyedObjects2D) this.data.clone();
402: return clone;
403: }
404: }