1 42 43 package org.jfree.data.statistics; 44 45 import java.io.Serializable ; 46 47 import org.jfree.util.PublicCloneable; 48 49 52 public class SimpleHistogramBin implements Comparable , 53 Cloneable , PublicCloneable, 54 Serializable { 55 56 57 private static final long serialVersionUID = 3480862537505941742L; 58 59 60 private double lowerBound; 61 62 63 private double upperBound; 64 65 69 private boolean includeLowerBound; 70 71 75 private boolean includeUpperBound; 76 77 78 private int itemCount; 79 80 86 public SimpleHistogramBin(double lowerBound, double upperBound) { 87 this(lowerBound, upperBound, true, true); 88 } 89 90 98 public SimpleHistogramBin(double lowerBound, double upperBound, 99 boolean includeLowerBound, 100 boolean includeUpperBound) { 101 if (lowerBound >= upperBound) { 102 throw new IllegalArgumentException ("Invalid bounds"); 103 } 104 this.lowerBound = lowerBound; 105 this.upperBound = upperBound; 106 this.includeLowerBound = includeLowerBound; 107 this.includeUpperBound = includeUpperBound; 108 this.itemCount = 0; 109 } 110 111 116 public double getLowerBound() { 117 return this.lowerBound; 118 } 119 120 125 public double getUpperBound() { 126 return this.upperBound; 127 } 128 129 134 public int getItemCount() { 135 return this.itemCount; 136 } 137 138 143 public void setItemCount(int count) { 144 this.itemCount = count; 145 } 146 147 155 public boolean accepts(double value) { 156 if (Double.isNaN(value)) { 157 return false; 158 } 159 if (value < this.lowerBound) { 160 return false; 161 } 162 if (value > this.upperBound) { 163 return false; 164 } 165 if (value == this.lowerBound) { 166 return this.includeLowerBound; 167 } 168 if (value == this.upperBound) { 169 return this.includeUpperBound; 170 } 171 return true; 172 } 173 174 182 public boolean overlapsWith(SimpleHistogramBin bin) { 183 if (this.upperBound < bin.lowerBound) { 184 return false; 185 } 186 if (this.lowerBound > bin.upperBound) { 187 return false; 188 } 189 if (this.upperBound == bin.lowerBound) { 190 return this.includeUpperBound && bin.includeLowerBound; 191 } 192 if (this.lowerBound == bin.upperBound) { 193 return this.includeLowerBound && bin.includeUpperBound; 194 } 195 return true; 196 } 197 198 207 public int compareTo(Object obj) { 208 if (!(obj instanceof SimpleHistogramBin)) { 209 return 0; 210 } 211 SimpleHistogramBin bin = (SimpleHistogramBin) obj; 212 if (this.lowerBound < bin.lowerBound) { 213 return -1; 214 } 215 if (this.lowerBound > bin.lowerBound) { 216 return 1; 217 } 218 if (this.upperBound < bin.upperBound) { 220 return -1; 221 } 222 if (this.upperBound > bin.upperBound) { 223 return 1; 224 } 225 return 0; 226 } 227 228 235 public boolean equals(Object obj) { 236 if (!(obj instanceof SimpleHistogramBin)) { 237 return false; 238 } 239 SimpleHistogramBin that = (SimpleHistogramBin) obj; 240 if (this.lowerBound != that.lowerBound) { 241 return false; 242 } 243 if (this.upperBound != that.upperBound) { 244 return false; 245 } 246 if (this.includeLowerBound != that.includeLowerBound) { 247 return false; 248 } 249 if (this.includeUpperBound != that.includeUpperBound) { 250 return false; 251 } 252 if (this.itemCount != that.itemCount) { 253 return false; 254 } 255 return true; 256 } 257 258 265 public Object clone() throws CloneNotSupportedException { 266 return super.clone(); 267 } 268 269 } 270 | Popular Tags |