comparison gnv-artifacts/src/main/java/de/intevation/gnv/jfreechart/PolygonDataset.java @ 657:af3f56758f59

merged gnv-artifacts/0.5
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:13:53 +0200
parents 92b7ccbf6163
children b1f5f2a8840f
comparison
equal deleted inserted replaced
590:5f5f273c8566 657:af3f56758f59
1 package de.intevation.gnv.jfreechart;
2
3 import java.util.List;
4 import java.util.Collection;
5 import java.util.ArrayList;
6
7 import org.jfree.data.Range;
8 import org.jfree.data.general.AbstractSeriesDataset;
9
10 /**
11 * @author Ingo Weinzierl <ingo.weinzierl@intevation.de>
12 */
13 public class PolygonDataset
14 extends AbstractSeriesDataset
15 {
16 /** PolygonSeries included in this Dataset */
17 private List data;
18
19
20 public PolygonDataset() {
21 data = new ArrayList();
22 }
23
24 public PolygonDataset(Collection series) {
25 data = new ArrayList(series);
26 }
27
28 public PolygonDataset(PolygonSeries series) {
29 this();
30
31 if (series != null) {
32 data.add(series);
33 }
34 }
35
36
37 public void addSeries(PolygonSeries series) {
38 if (series == null)
39 throw new IllegalArgumentException("Null 'series' argument.");
40
41 data.add(series);
42 }
43
44 public void addAllSeries(Collection<PolygonSeries> series) {
45 data.addAll(series);
46 }
47
48 public Range getDomainBounds() {
49 double lower = Double.POSITIVE_INFINITY;
50 double upper = Double.NEGATIVE_INFINITY;
51 int seriesCount = getSeriesCount();
52
53 for (int s = 0; s < seriesCount; s++) {
54 PolygonSeries series = getSeries(s);
55
56 Range domainRange = series.getDomainBounds();
57 double minX = domainRange.getLowerBound();
58 if (!Double.isNaN(minX)) {
59 lower = Math.min(lower, minX);
60 }
61
62 double maxX = domainRange.getUpperBound();
63 if (!Double.isNaN(maxX)) {
64 upper = Math.max(upper, maxX);
65 }
66 }
67
68 return new Range(lower, upper);
69 }
70
71
72 public Range getRangeBounds() {
73 double lower = Double.POSITIVE_INFINITY;
74 double upper = Double.NEGATIVE_INFINITY;
75 int seriesCount = getSeriesCount();
76
77 for (int i = 0; i < seriesCount; i++) {
78 PolygonSeries series = getSeries(i);
79
80 Range range = series.getRangeBounds();
81 double minX = range.getLowerBound();
82 if (!Double.isNaN(minX)) {
83 lower = Math.min(lower, minX);
84 }
85
86 double maxX = range.getUpperBound();
87 if (!Double.isNaN(maxX)) {
88 upper = Math.max(upper, maxX);
89 }
90 }
91
92 return new Range(lower, upper);
93 }
94
95
96 public int getSeriesCount() {
97 return data.size();
98 }
99
100
101 public Comparable getSeriesKey(int series) {
102 return ((PolygonSeries)data.get(series)).getKey();
103 }
104
105
106 public PolygonSeries getSeries(int idx) {
107 return (PolygonSeries)data.get(idx);
108 }
109 }
110 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org