1 | public class CustomCategoryURLGenerator implements CategoryURLGenerator,↵ | | 1 | public class CustomXYURLGenerator implements XYURLGenerator,↵
|
2 | Cloneable,↵ | | 2 | Cloneable,↵
|
3 | PublicCloneable, Serializable {↵ | | 3 | PublicCloneable, Serializable {↵
|
|
| | | 4 | /** For serialization. */↵
|
| | | 5 | private static final long serialVersionUID = -8565933356596551832L;↵
|
|
4 | /** Storage for the URLs. */↵ | | 6 | /** Storage for the URLs. */↵
|
5 | private ArrayList urlSeries = new ArrayList();↵ | | 7 | private ArrayList urlSeries = new ArrayList();↵
|
|
6 | /**↵ | | 8 | /**↵
|
7 | * Default constructor.↵ | | 9 | * Default constructor.↵
|
8 | */↵ | | 10 | */↵
|
9 | public CustomCategoryURLGenerator() {↵ | | 11 | public CustomXYURLGenerator() {↵
|
10 | super();↵ | | 12 | super();↵
|
11 | }↵ | | 13 | }↵
|
|
12 | /**↵ | | 14 | /**↵
|
13 | * Returns the number of URL lists stored by the renderer.↵ | | 15 | * Returns the number of URL lists stored by the renderer.↵
|
14 | *↵ | | 16 | *↵
|
15 | * @return The list count.↵ | | 17 | * @return The list count.↵
|
16 | */↵ | | 18 | */↵
|
17 | public int getListCount() {↵ | | 19 | public int getListCount() {↵
|
18 | return this.urlSeries.size();↵ | | 20 | return this.urlSeries.size();↵
|
19 | }↵ | | 21 | }↵
|
|
20 | /**↵ | | 22 | /**↵
|
21 | * Returns the number of URLs in a given list.↵ | | 23 | * Returns the number of URLs in a given list.↵
|
22 | *↵ | | 24 | *↵
|
23 | * @param list the list index (zero based).↵ | | 25 | * @param list the list index (zero based).↵
|
24 | *↵ | | 26 | *↵
|
25 | * @return The URL count.↵ | | 27 | * @return The URL count.↵
|
26 | */↵ | | 28 | */↵
|
27 | public int getURLCount(int list) {↵ | | 29 | public int getURLCount(int list) {↵
|
28 | int result = 0;↵ | | 30 | int result = 0;↵
|
29 | List urls = (List) this.urlSeries.get(list);↵ | | 31 | List urls = (List) this.urlSeries.get(list);↵
|
30 | if (urls != null) {↵ | | 32 | if (urls != null) {↵
|
31 | result = urls.size();↵ | | 33 | result = urls.size();↵
|
32 | }↵ | | 34 | }↵
|
33 | return result;↵ | | 35 | return result;↵
|
34 | }↵ | | 36 | }↵
|
|
35 | /**↵ | | 37 | /**↵
|
36 | * Returns the URL for an item.↵ | | 38 | * Returns the URL for an item.↵
|
37 | *↵ | | 39 | *↵
|
38 | * @param series the series index.↵ | | 40 | * @param series the series index.↵
|
39 | * @param item the item index.↵ | | 41 | * @param item the item index.↵
|
40 | *↵ | | 42 | *↵
|
41 | * @return The URL (possibly null ).↵ | | 43 | * @return The URL (possibly null ).↵
|
42 | */↵ | | 44 | */↵
|
43 | public String getURL(int series, int item) {↵ | | 45 | public String getURL(int series, int item) {↵
|
44 | String result = null;↵ | | 46 | String result = null;↵
|
45 | if (series < getListCount()) {↵ | | 47 | if (series < getListCount()) {↵
|
46 | List urls = (List) this.urlSeries.get(series);↵ | | 48 | List urls = (List) this.urlSeries.get(series);↵
|
47 | if (urls != null) {↵ | | 49 | if (urls != null) {↵
|
48 | if (item < urls.size()) {↵ | | 50 | if (item < urls.size()) {↵
|
49 | result = (String) urls.get(item);↵ | | 51 | result = (String) urls.get(item);↵
|
50 | }↵ | | 52 | }↵
|
51 | }↵ | | 53 | }↵
|
52 | }↵ | | 54 | }↵
|
53 | return result;↵ | | 55 | return result;↵
|
54 | }↵ | | 56 | }↵
|
|
55 | /**↵ | | 57 | /**↵
|
56 | * Generates a URL.↵ | | 58 | * Generates a URL.↵
|
57 | *↵ | | 59 | *↵
|
58 | * @param dataset the dataset (ignored in this implementation).↵ | | 60 | * @param dataset the dataset.↵
|
59 | * @param series the series (zero-based index).↵ | | 61 | * @param series the series (zero-based index).↵
|
60 | * @param item the item (zero-based index).↵ | | 62 | * @param item the item (zero-based index).↵
|
61 | *↵ | | 63 | *↵
|
62 | * @return A string containing the URL (possibly null ).↵ | | 64 | * @return A string containing the URL (possibly null ).↵
|
63 | */↵ | | 65 | */↵
|
64 | public String generateURL(CategoryDataset dataset, int series, int item) {↵ | | 66 | public String generateURL(XYDataset dataset, int series, int item) {↵
|
65 | return getURL(series, item);↵ | | 67 | return getURL(series, item);↵
|
66 | }↵ | | 68 | }↵
|
|
67 | /**↵ | | 69 | /**↵
|
68 | * Adds a list of URLs.↵ | | 70 | * Adds a list of URLs.↵
|
69 | *↵ | | 71 | *↵
|
70 | * @param urls the list of URLs (null permitted↵ | | 72 | * @param urls the list of URLs (null permitted, the list↵
|
71 | ).↵ | | 73 | * is copied).↵
|
72 | */↵ | | 74 | */↵
|
73 | public void addURLSeries(List urls) {↵ | | 75 | public void addURLSeries(List urls) {↵
|
74 | List listToAdd = null;↵ | | 76 | List listToAdd = null;↵
|
75 | if (urls != null) {↵ | | 77 | if (urls != null) {↵
|
76 | listToAdd = new java.util.ArrayList(urls);↵ | | 78 | listToAdd = new java.util.ArrayList(urls);↵
|
77 | }↵ | | 79 | }↵
|
78 | this.urlSeries.add(listToAdd);↵ | | 80 | this.urlSeries.add(listToAdd);↵
|
79 | }↵ | | 81 | }↵
|
|
80 | /**↵ | | 82 | /**↵
|
81 | * Tests if this object is equal to another.↵ | | 83 | * Tests this ↵
|
82 | *↵ | | |
|
83 | * @param obj the other object↵ | | 84 | generator for equality with an arbitrary object.↵
|
| | | 85 | *↵
|
84 | .↵ | | 86 | * @param obj the object (null permitted).↵
|
85 | *↵ | | 87 | *↵
|
86 | * @return A boolean.↵ | | 88 | * @return A boolean.↵
|
87 | */↵ | | 89 | */↵
|
88 | public boolean equals(Object obj) {↵ | | 90 | public boolean equals(Object obj) {↵
|
89 | if (obj == this) {↵ | | 91 | if (obj == this) {↵
|
90 | return true;↵ | | 92 | return true;↵
|
91 | }↵ | | 93 | }↵
|
92 | if (!(obj instanceof CustomCategoryURLGenerator)) {↵ | | 94 | if (!(obj instanceof CustomXYURLGenerator)) {↵
|
93 | return false;↵ | | 95 | return false;↵
|
94 | }↵ | | 96 | }↵
|
95 | CustomCategoryURLGenerator generator = (CustomCategoryURLGenerator) obj;↵ | | 97 | CustomXYURLGenerator that = (CustomXYURLGenerator) obj;↵
|
96 | int listCount = getListCount();↵ | | 98 | int listCount = getListCount();↵
|
97 | if (listCount != generator.getListCount()) {↵ | | 99 | if (listCount != that.getListCount()) {↵
|
98 | return false;↵ | | 100 | return false;↵
|
99 | }↵ | | 101 | }↵
|
|
100 | for (int series = 0; series < listCount; series++) {↵ | | 102 | for (int series = 0; series < listCount; series++) {↵
|
101 | int urlCount = getURLCount(series);↵ | | 103 | int urlCount = getURLCount(series);↵
|
102 | if (urlCount != generator.getURLCount(series)) {↵ | | 104 | if (urlCount != that.getURLCount(series)) {↵
|
103 | return false;↵ | | 105 | return false;↵
|
104 | }↵ | | 106 | }↵
|
|
105 | for (int item = 0; item < urlCount; item++) {↵ | | 107 | for (int item = 0; item < urlCount; item++) {↵
|
106 | String u1 = getURL(series, item);↵ | | 108 | String u1 = getURL(series, item);↵
|
107 | String u2 = generator.getURL(series, item);↵ | | 109 | String u2 = that.getURL(series, item);↵
|
108 | if (u1 != null) {↵ | | 110 | if (u1 != null) {↵
|
109 | if (!u1.equals(u2)) {↵ | | 111 | if (!u1.equals(u2)) {↵
|
110 | return false;↵ | | 112 | return false;↵
|
111 | }↵ | | 113 | }↵
|
112 | }↵ | | 114 | }↵
|
113 | else {↵ | | 115 | else {↵
|
114 | if (u2 != null) {↵ | | 116 | if (u2 != null) {↵
|
115 | return false;↵ | | 117 | return false;↵
|
116 | }↵ | | 118 | }↵
|
117 | }↵ | | 119 | }↵
|
118 | }↵ | | 120 | }↵
|
119 | }↵ | | 121 | }↵
|
120 | return true;↵ | | 122 | return true;↵
|
|
121 | }↵ | | 123 | }↵
|
|
122 | /**↵ | | 124 | /**↵
|
123 | * Returns a new generator that is a copy of, and independent from, this↵ | | 125 | * Returns a new generator that is a copy of, and independent from, this↵
|
124 | * generator.↵ | | 126 | * generator.↵
|
125 | *↵ | | 127 | *↵
|
126 | * @return A clone.↵ | | 128 | * @return A clone.↵
|
127 | */↵ | | 129 | */↵
|
128 | public Object clone() throws CloneNotSupportedException {↵ | | 130 | public Object clone() throws CloneNotSupportedException {↵
|
129 | CustomCategoryURLGenerator clone↵ | | 131 | CustomXYURLGenerator clone↵
|
130 | = (CustomCategoryURLGenerator) super.clone();↵ | | 132 | = (CustomXYURLGenerator) super.clone();↵
|
131 | clone.urlSeries = new java.util.ArrayList(this.urlSeries);↵ | | 133 | clone.urlSeries = new java.util.ArrayList(this.urlSeries);↵
|
132 | return clone;↵ | | 134 | return clone;↵
|
133 | | | 135 |
|