1 23 package info.monitorenter.util; 24 25 import java.io.Serializable ; 26 27 36 public class Range implements Serializable { 37 38 41 private static final long serialVersionUID = 3760565278089754419L; 42 43 44 public static final Range RANGE_UNBOUNDED = new Range(-Double.MAX_VALUE, +Double.MAX_VALUE); 45 46 47 protected double m_min; 48 49 50 protected double m_max; 51 52 62 public Range(final double min, final double max) { 63 if (min == Double.NaN) { 64 throw new IllegalArgumentException ("Cannot work on Double.NaN for min."); 65 } 66 MathUtil.assertDouble(min); 67 MathUtil.assertDouble(max); 68 if (min < max) { 69 this.m_min = min; 70 this.m_max = max; 71 } else { 72 this.m_min = max; 73 this.m_max = min; 74 } 75 } 76 77 83 public double getMin() { 84 return this.m_min; 85 } 86 87 93 public double getMax() { 94 return this.m_max; 95 } 96 97 103 public double getExtent() { 104 return this.m_max - this.m_min; 105 } 106 107 118 public boolean ensureContained(final double contain) { 119 boolean ret = false; 120 if (contain < this.m_min) { 121 ret = true; 122 this.m_min = contain; 123 } else if (contain > this.m_max) { 124 ret = true; 125 this.m_max = contain; 126 } 127 return ret; 128 } 129 130 139 public boolean isContained(final double contained) { 140 return ((this.m_min <= contained) && (this.m_max >= contained)); 141 } 142 143 146 public String toString() { 147 StringBuffer ret = new StringBuffer ("Range["); 148 ret.append(this.m_min).append(','); 149 ret.append(this.m_max).append(']'); 150 return ret.toString(); 151 } 152 } 153 | Popular Tags |