File: DoubleRange.java

package info (click to toggle)
gpsprune 10-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,220 kB
  • ctags: 3,013
  • sloc: java: 22,662; sh: 23; makefile: 16; python: 15
file content (82 lines) | stat: -rw-r--r-- 1,310 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package tim.prune.data;

/**
 * Represents a range of doubles, holding the maximum and
 * minimum values.  Values can be positive or negative
 */
public class DoubleRange
{
	private boolean _empty = true;
	private double _min = 0.0, _max = 0.0;


	/** Empty constructor, cleared to zeroes */
	public DoubleRange() {}

	/**
	 * Constructor giving two initial values
	 * @param inValue1 first value
	 * @param inValue2 second value
	 */
	public DoubleRange(double inValue1, double inValue2)
	{
		addValue(inValue1);
		addValue(inValue2);
	}

	/**
	 * Clear for a new calculation
	 */
	public void clear()
	{
		_min = _max = 0.0;
		_empty = true;
	}


	/**
	 * Add a value to the range
	 * @param inValue value to add
	 */
	public void addValue(double inValue)
	{
		if (inValue < _min || _empty) _min = inValue;
		if (inValue > _max || _empty) _max = inValue;
		_empty = false;
	}


	/**
	 * @return true if data values were found
	 */
	public boolean hasData()
	{
		return (!_empty);
	}


	/**
	 * @return minimum value, or 0.0 if none found
	 */
	public double getMinimum()
	{
		return _min;
	}


	/**
	 * @return maximum value, or 0.0 if none found
	 */
	public double getMaximum()
	{
		return _max;
	}

	/**
	 * @return range, as maximum - minimum
	 */
	public double getRange()
	{
		return _max - _min;
	}
}