]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/data/Unit.java
Version 14, October 2012
[GpsPrune.git] / tim / prune / data / Unit.java
1 package tim.prune.data;
2
3 /**
4  * Class to represent a single distance or speed unit
5  * such as kilometres, mph, feet etc
6  */
7 public class Unit
8 {
9         private String _nameKey = null;
10         private double _multFactorFromStd = 1.0;
11         private boolean _isStandard = false;
12
13         /**
14          * Unit constructor
15          * @param inNameKey name key
16          * @param inMultFactor multiplication factor from standard units
17          */
18         public Unit(String inNameKey, double inMultFactor)
19         {
20                 _nameKey = inNameKey;
21                 _multFactorFromStd = inMultFactor;
22                 _isStandard = false;
23         }
24
25         /**
26          * Unit constructor for standard unit
27          * @param inNameKey name key
28          */
29         public Unit(String inNameKey)
30         {
31                 _nameKey = inNameKey;
32                 _multFactorFromStd = 1.0;
33                 _isStandard = true;
34         }
35
36         /**
37          * Unit constructor
38          * @param inParent parent unit
39          * @param inSuffix suffix to name key
40          */
41         public Unit(Unit inParent, String inSuffix)
42         {
43                 _nameKey = inParent._nameKey + inSuffix;
44                 _multFactorFromStd = inParent._multFactorFromStd;
45                 _isStandard = inParent._isStandard;
46         }
47
48         /**
49          * @return name key
50          */
51         public String getNameKey() {
52                 return "units." + _nameKey;
53         }
54
55         /**
56          * @return shortname key
57          */
58         public String getShortnameKey() {
59                 return getNameKey() + ".short";
60         }
61
62         /**
63          * @return multiplication factor from standard units
64          */
65         public double getMultFactorFromStd() {
66                 return _multFactorFromStd;
67         }
68
69         /**
70          * @return true if this is the standard unit (mult factor 1.0)
71          */
72         public boolean isStandard() {
73                 return _isStandard;
74         }
75 }