/** * Returns value of a preference as a String * * @param key - The name of the preference * @return The value of the preference */ public static String getString(String key) { if (table.containsKey(key)) { return table.getString(key); } else { System.err.println("Preference not found: " + key); set(key, "0"); return "0"; } }
/** Overwrites the file with current preferences */ public static void write() { BufferedWriter out; if (keys.isEmpty()) { // So we don't accidentally delete the preferences file return; } try { out = new BufferedWriter(new FileWriter("/home/lvuser/Preferences.txt")); for (int i = 0; i < keys.size(); i++) { if (!keys.get(i).equals("")) { // Empty String indicates a blank line String line = keys.get(i) + DIVIDER + table.getString(keys.get(i)); out.write(line); } out.newLine(); } out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } }
/** * Returns the value at the specified key. * * @param key the key * @param defaultValue The value returned if the key is undefined * @return the value * @throws NetworkTableKeyNotDefined if there is no value mapped to by the key * @throws IllegalArgumentException if the value mapped to by the key is not a string * @throws IllegalArgumentException if the key is null */ public static String getString(String key, String defaultValue) { return table.getString(key, defaultValue); }
/** * Returns the value at the specified key. * * @param key the key * @return the value * @throws NetworkTableKeyNotDefined if there is no value mapped to by the key * @throws IllegalArgumentException if the value mapped to by the key is not a string * @throws IllegalArgumentException if the key is null */ public static String getString(String key) throws TableKeyNotDefinedException { return table.getString(key); }