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