altosui: Explicitly initialize Altos class
authorKeith Packard <keithp@keithp.com>
Thu, 5 Aug 2010 17:40:17 +0000 (13:40 -0400)
committerKeith Packard <keithp@keithp.com>
Thu, 5 Aug 2010 17:40:17 +0000 (13:40 -0400)
Because the Altos class is never instantiated, the static initializers
are never called, leaving the string to state mapping empty. Hand-code
the call to the initialer instead.

Signed-off-by: Keith Packard <keithp@keithp.com>
ao-tools/altosui/Altos.java

index bda4080e9bfbcf82f8cc914e10722d28686e0a8e..6ea7b43ceffaf6ba23e362cfaf3b550a9f8fd45c 100644 (file)
@@ -54,6 +54,10 @@ public class Altos {
        static final int ao_flight_invalid = 9;
 
        static HashMap<String,Integer>  string_to_state = new HashMap<String,Integer>();
+
+       static boolean map_initialized = false;
+
+       static void initialize_map()
        {
                string_to_state.put("startup", ao_flight_startup);
                string_to_state.put("idle", ao_flight_idle);
@@ -65,6 +69,7 @@ public class Altos {
                string_to_state.put("main", ao_flight_main);
                string_to_state.put("landed", ao_flight_landed);
                string_to_state.put("invalid", ao_flight_invalid);
+               map_initialized = true;
        }
 
        static String[] state_to_string = {
@@ -81,6 +86,8 @@ public class Altos {
        };
 
        static public int state(String state) {
+               if (!map_initialized)
+                       initialize_map();
                if (string_to_state.containsKey(state))
                        return string_to_state.get(state);
                return ao_flight_invalid;