GUACAMOLE-320: Add parse() convenience function for TextField which interprets empty strings as equivalent to null.
This commit is contained in:
1 parent
04c70c7e49
commit
ed066c88e7
1 file changed
+21
@@ -35,4 +35,25 @@ public class TextField extends Field {
|
|||||||
super(name, Field.Type.TEXT);
|
super(name, Field.Type.TEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the given string, interpreting empty strings as equivalent to
|
||||||
|
* null. For all other cases, the given string is returned verbatim.
|
||||||
|
*
|
||||||
|
* @param str
|
||||||
|
* The string to parse, which may be null.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* The given string, or null if the given string was null or empty.
|
||||||
|
*/
|
||||||
|
public static String parse(String str) {
|
||||||
|
|
||||||
|
// Return null if no value provided
|
||||||
|
if (str == null || str.isEmpty())
|
||||||
|
return null;
|
||||||
|
|
||||||
|
// Otherwise, return string unmodified
|
||||||
|
return str;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user