/** * @return the starting range for the entire {@link Histogram}. All values * within all bins will be >= this value; */ public double getStart() { if (bins.isEmpty()) { return Double.NEGATIVE_INFINITY; } else { return bins.get(0).getStart(); } }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Bin other = (Bin) obj; if (getCount() != other.getCount()) return false; if (Double.doubleToLongBits(getStart()) != Double.doubleToLongBits(other.getStart())) return false; if (Double.doubleToLongBits(getStart()) != Double.doubleToLongBits(other.getStart())) return false; return true; }
static Bin collapse(List<Bin> bins) { long total = 0L; for (Bin b : bins) { total += b.getCount(); } Bin firstBin = bins.get(0); Bin lastBin = bins.get(bins.size() - 1); return new Bin(total, firstBin.getStart(), lastBin.getEnd()); }
private List<Bin> growTo(List<Bin> bins, double endValue, int minCount) { int neededBins = Double.POSITIVE_INFINITY != endValue ? definition.getBinForValue(endValue) : minCount; if (neededBins < minCount) { neededBins = minCount; } List<Bin> grownBins = new ArrayList<Bin>(bins); if (grownBins.isEmpty()) { grownBins.add(emptyBinAt(0)); } if (grownBins.get(0).getStart() != 0) { // fill bins from 0 to start double fillTo = grownBins.get(0).getStart(); List<Bin> prefixBins = new ArrayList<Bin>(); BinDefinition binDef; int count = 0; do { binDef = definition.getBinDefinition(count); count++; prefixBins.add(new Bin(0, binDef.getStart(), binDef.getEnd())); } while (fillTo > binDef.getEnd()); grownBins.addAll(0, prefixBins); } // fill bins from end to needed bins while (grownBins.size() < neededBins) { grownBins.add(emptyBinAt(grownBins.size())); } return Collections.unmodifiableList(grownBins); }
@Override public int hashCode() { int result = MathUtil.hashValue(getCount()); result = 31 * result + MathUtil.hashValue(getStart()); result = 31 * result + MathUtil.hashValue(getEnd()); return result; }