1 44 package org.jfree.chart.urls; 45 46 import java.io.Serializable ; 47 import java.util.ArrayList ; 48 import java.util.HashMap ; 49 import java.util.Iterator ; 50 import java.util.Map ; 51 import java.util.Set ; 52 53 import org.jfree.data.general.PieDataset; 54 import org.jfree.util.PublicCloneable; 55 56 59 public class CustomPieURLGenerator implements PieURLGenerator, 60 Cloneable , 61 PublicCloneable, 62 Serializable { 63 64 65 private static final long serialVersionUID = 7100607670144900503L; 66 67 68 private ArrayList urls; 69 70 73 public CustomPieURLGenerator() { 74 this.urls = new ArrayList (); 75 } 76 77 86 public String generateURL(PieDataset dataset, Comparable key, 87 int pieIndex) { 88 return getURL(key, pieIndex); 89 } 90 91 96 public int getListCount() { 97 return this.urls.size(); 98 } 99 100 107 public int getURLCount(int list) { 108 109 int result = 0; 110 Map urlMap = (Map ) this.urls.get(list); 111 if (urlMap != null) { 112 result = urlMap.size(); 113 } 114 return result; 115 } 116 117 125 public String getURL(Comparable key, int pieItem) { 126 127 String result = null; 128 129 if (pieItem < getListCount()) { 130 Map urlMap = (Map ) this.urls.get(pieItem); 131 if (urlMap != null) { 132 result = (String ) urlMap.get(key); 133 } 134 } 135 136 return result; 137 } 138 139 144 public void addURLs(Map urlMap) { 145 this.urls.add(urlMap); 146 } 147 148 155 public boolean equals(Object o) { 156 157 if (o == this) { 158 return true; 159 } 160 161 if (o instanceof CustomPieURLGenerator) { 162 CustomPieURLGenerator generator = (CustomPieURLGenerator) o; 163 if (getListCount() != generator.getListCount()) { 164 return false; 165 } 166 Set keySet; 167 for (int pieItem = 0; pieItem < getListCount(); pieItem++) { 168 if (getURLCount(pieItem) != generator.getURLCount(pieItem)) { 169 return false; 170 } 171 keySet = ((HashMap ) this.urls.get(pieItem)).keySet(); 172 String key; 173 for (Iterator i = keySet.iterator(); i.hasNext();) { 174 key = (String ) i.next(); 175 if (!getURL(key, pieItem).equals( 176 generator.getURL(key, pieItem))) { 177 return false; 178 } 179 } 180 } 181 return true; 182 } 183 return false; 184 } 185 186 193 public Object clone() throws CloneNotSupportedException { 194 CustomPieURLGenerator urlGen = new CustomPieURLGenerator(); 195 Map map; 196 Map newMap; 197 String key; 198 199 for (Iterator i = this.urls.iterator(); i.hasNext();) { 200 map = (Map ) i.next(); 201 202 newMap = new HashMap (); 203 for (Iterator j = map.keySet().iterator(); j.hasNext();) { 204 key = (String ) j.next(); 205 newMap.put(key, map.get(key)); 206 } 207 208 urlGen.addURLs(newMap); 209 newMap = null; 210 } 211 212 return urlGen; 213 } 214 215 } 216 | Popular Tags |