An empty string could still be returned when a non empty string is required. Related to #3381

This commit is contained in:
Federico Fissore 2015-06-22 11:00:50 +02:00
parent a49f1b264a
commit 8e76fb87dc
2 changed files with 9 additions and 4 deletions

View File

@ -146,6 +146,11 @@ public class PreferencesData {
return (value == null) ? defaultValue : value;
}
static public String getNonEmpty(String attribute, String defaultValue) {
String value = get(attribute, defaultValue);
return ("".equals(value)) ? defaultValue : value;
}
public static boolean has(String key) {
return prefs.containsKey(key);
}

View File

@ -50,27 +50,27 @@ public class Serial implements SerialPortEventListener {
public Serial() throws SerialException {
this(PreferencesData.get("serial.port"),
PreferencesData.getInteger("serial.debug_rate", 9600),
PreferencesData.get("serial.parity", "N").charAt(0),
PreferencesData.getNonEmpty("serial.parity", "N").charAt(0),
PreferencesData.getInteger("serial.databits", 8),
PreferencesData.getFloat("serial.stopbits", 1));
}
public Serial(int irate) throws SerialException {
this(PreferencesData.get("serial.port"), irate,
PreferencesData.get("serial.parity", "N").charAt(0),
PreferencesData.getNonEmpty("serial.parity", "N").charAt(0),
PreferencesData.getInteger("serial.databits", 8),
PreferencesData.getFloat("serial.stopbits", 1));
}
public Serial(String iname, int irate) throws SerialException {
this(iname, irate, PreferencesData.get("serial.parity", "N").charAt(0),
this(iname, irate, PreferencesData.getNonEmpty("serial.parity", "N").charAt(0),
PreferencesData.getInteger("serial.databits", 8),
PreferencesData.getFloat("serial.stopbits", 1));
}
public Serial(String iname) throws SerialException {
this(iname, PreferencesData.getInteger("serial.debug_rate", 9600),
PreferencesData.get("serial.parity", "N").charAt(0),
PreferencesData.getNonEmpty("serial.parity", "N").charAt(0),
PreferencesData.getInteger("serial.databits", 8),
PreferencesData.getFloat("serial.stopbits", 1));
}