1 package tim.prune.data;
4 * Represents a range of doubles, holding the maximum and
5 * minimum values. Values can be positive or negative
7 public class DoubleRange
9 private boolean _empty = true;
10 private double _min = 0.0, _max = 0.0;
13 /** Empty constructor, cleared to zeroes */
14 public DoubleRange() {}
17 * Constructor giving two initial values
18 * @param inValue1 first value
19 * @param inValue2 second value
21 public DoubleRange(double inValue1, double inValue2)
28 * Clear for a new calculation
38 * Add a value to the range
39 * @param inValue value to add
41 public void addValue(double inValue)
43 if (inValue < _min || _empty) _min = inValue;
44 if (inValue > _max || _empty) _max = inValue;
49 * Combine this range with another one
50 * @param inOtherRange other range to add to this one
52 public void combine(DoubleRange inOtherRange)
54 if (inOtherRange != null && inOtherRange.getRange() > 1.0)
56 addValue(inOtherRange.getMinimum());
57 addValue(inOtherRange.getMaximum());
62 * @return true if data values were found
64 public boolean hasData()
71 * @return minimum value, or 0.0 if none found
73 public double getMinimum()
80 * @return maximum value, or 0.0 if none found
82 public double getMaximum()
88 * @return range, as maximum - minimum
90 public double getRange()
96 * @return mid value, halfway between min and max
98 public double getMidValue()
100 return (_max + _min) / 2.0;
104 * Copy this range into a new object, which can then be modified without changing this one
105 * @return deep copy of this object
107 public DoubleRange copy()
109 if (_empty) return new DoubleRange();
110 return new DoubleRange(_min, _max);