1 48 49 package org.jfree.chart.entity; 50 51 import java.io.Serializable ; 52 import java.util.Collection ; 53 import java.util.Collections ; 54 import java.util.Iterator ; 55 import java.util.List ; 56 57 import org.jfree.util.ObjectUtilities; 58 59 62 public class StandardEntityCollection implements EntityCollection, 63 Cloneable , Serializable { 64 65 66 private static final long serialVersionUID = 5384773031184897047L; 67 68 69 private List entities; 70 71 74 public StandardEntityCollection() { 75 this.entities = new java.util.ArrayList (); 76 } 77 78 83 public int getEntityCount() { 84 return this.entities.size(); 85 } 86 87 94 public ChartEntity getEntity(int index) { 95 return (ChartEntity) this.entities.get(index); 96 } 97 98 101 public void clear() { 102 this.entities.clear(); 103 } 104 105 110 public void add(ChartEntity entity) { 111 if (entity == null) { 112 throw new IllegalArgumentException ("Null 'entity' argument."); 113 } 114 this.entities.add(entity); 115 } 116 117 122 public void addAll(EntityCollection collection) { 123 this.entities.addAll(collection.getEntities()); 124 } 125 126 135 public ChartEntity getEntity(double x, double y) { 136 int entityCount = this.entities.size(); 137 for (int i = entityCount - 1; i >= 0; i--) { 138 ChartEntity entity = (ChartEntity) this.entities.get(i); 139 if (entity.getArea().contains(x, y)) { 140 return entity; 141 } 142 } 143 return null; 144 } 145 146 151 public Collection getEntities() { 152 return Collections.unmodifiableCollection(this.entities); 153 } 154 155 160 public Iterator iterator() { 161 return this.entities.iterator(); 162 } 163 164 171 public boolean equals(Object obj) { 172 if (obj == this) { 173 return true; 174 } 175 if (obj instanceof StandardEntityCollection) { 176 StandardEntityCollection that = (StandardEntityCollection) obj; 177 return ObjectUtilities.equal(this.entities, that.entities); 178 } 179 return false; 180 } 181 182 189 public Object clone() throws CloneNotSupportedException { 190 return super.clone(); 191 } 192 193 } 194 | Popular Tags |