1 package tim.prune.data;
4 * List of all possible unit sets, for example
5 * metric, imperial, nautical
7 public abstract class UnitSetLibrary
9 // Distance units - all conversion factors are from metres
10 /** Units for feet (used for loading and converting values) */
11 public static final Unit UNITS_FEET = new Unit("feet", 3.2808);
12 /** Units for metres */
13 public static final Unit UNITS_METRES = new Unit("metres");
15 public static final Unit UNITS_KILOMETRES = new Unit("kilometres", 1/1000.0);
16 /** Units for miles */
17 public static final Unit UNITS_MILES = new Unit("miles", 1/1609.3);
18 /** Units for nautical miles */
19 public static final Unit UNITS_NAUTICAL_MILES = new Unit("nauticalmiles", 1/1852.0);
21 /** Array of available unit sets */
22 private static UnitSet[] _sets = {
23 new UnitSet("unitset.kilometres", UNITS_KILOMETRES, UNITS_METRES, Altitude.Format.METRES),
24 new UnitSet("unitset.miles", UNITS_MILES, UNITS_FEET, Altitude.Format.FEET),
25 new UnitSet("unitset.nautical", UNITS_NAUTICAL_MILES, UNITS_FEET, Altitude.Format.FEET)
29 * @return number of available unit sets
31 public static int getNumUnitSets() {
36 * Get the specified unit set
37 * @param inIndex index of set starting from 0
38 * @return specified unit set or the default one if index out of range
40 public static UnitSet getUnitSet(int inIndex)
42 if (inIndex >= 0 && inIndex < getNumUnitSets()) {
43 return _sets[inIndex];
49 * Get the unit set specified by the given key
50 * @param inKey key to look for
51 * @return unit set with given key, or default set if key not found
53 public static UnitSet getUnitSet(String inKey)
55 // Loop over all available unit sets
56 for (int i=0; i<getNumUnitSets(); i++)
58 UnitSet set = getUnitSet(i);
59 if (set.getNameKey().equals(inKey)) {
63 // Not found in list, so just return the first one