001 package hirondelle.web4jtools.metrics.histogram; 002 003 /** 004 * Model Object for an element of a histogram, whose elements have 005 * numeric ranges. 006 * 007 * <P>This class is mutable. 008 */ 009 public final class Bucket { 010 011 /** 012 * Full constructor. 013 * 014 * <P>Min must be less than max. 015 */ 016 public Bucket(int aMin, int aMax){ 017 fMin = aMin; 018 fMax = aMax; 019 validateState(); 020 } 021 022 /** Special constructor for the 'last' bucket, which has no upper limit. */ 023 public Bucket(Integer aMin) { 024 fMin = aMin; 025 fMax = Integer.MAX_VALUE; 026 } 027 028 /** Increase the number of items in this bucket by one. */ 029 public void incrementCount(){ ++fCount; } 030 /** Return the number of items in this bucket. */ 031 public Integer getCount(){ return fCount; } 032 033 public Integer getMin(){ return fMin; } 034 public Integer getMax() { 035 return fMax == Integer.MAX_VALUE ? null : fMax; 036 } 037 038 // PRIVATE // 039 private int fMin; 040 private int fMax; 041 private int fCount; 042 043 private void validateState() { 044 if ( fMin >= fMax ) { 045 throw new IllegalArgumentException("Min must me less than max. Min :" + fMin + " Max : " + fMax); 046 } 047 } 048 }