File: Unit.java

package info (click to toggle)
gpsprune 17-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,984 kB
  • ctags: 5,218
  • sloc: java: 39,403; sh: 25; makefile: 17; python: 15
file content (86 lines) | stat: -rw-r--r-- 1,746 bytes parent folder | download | duplicates (6)
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
83
84
85
86
package tim.prune.data;

/**
 * Class to represent a single distance or speed unit
 * such as kilometres, mph, feet etc
 */
public class Unit
{
	private String _nameKey = null;
	private double _multFactorFromStd = 1.0;
	private boolean _isStandard = false;

	/**
	 * Unit constructor
	 * @param inNameKey name key
	 * @param inMultFactor multiplication factor from standard units
	 */
	public Unit(String inNameKey, double inMultFactor)
	{
		_nameKey = inNameKey;
		_multFactorFromStd = inMultFactor;
		_isStandard = false;
	}

	/**
	 * Unit constructor for standard unit
	 * @param inNameKey name key
	 */
	public Unit(String inNameKey)
	{
		_nameKey = inNameKey;
		_multFactorFromStd = 1.0;
		_isStandard = true;
	}

	/**
	 * Unit constructor
	 * @param inParent parent unit
	 * @param inSuffix suffix to name key
	 */
	public Unit(Unit inParent, String inSuffix)
	{
		this(inParent, inSuffix, 1.0);
	}

	/**
	 * Unit constructor
	 * @param inParent parent unit
	 * @param inSuffix suffix to name key
	 * @param inFactor additional time factor to apply
	 */
	public Unit(Unit inParent, String inSuffix, double inFactor)
	{
		_nameKey = inParent._nameKey + inSuffix;
		_multFactorFromStd = inParent._multFactorFromStd * inFactor;
		_isStandard = inParent._isStandard;
	}

	/**
	 * @return name key
	 */
	public String getNameKey() {
		return "units." + _nameKey;
	}

	/**
	 * @return shortname key
	 */
	public String getShortnameKey() {
		return getNameKey() + ".short";
	}

	/**
	 * @return multiplication factor from standard units
	 */
	public double getMultFactorFromStd() {
		return _multFactorFromStd;
	}

	/**
	 * @return true if this is the standard unit (mult factor 1.0)
	 */
	public boolean isStandard() {
		return _isStandard;
	}
}