From ecb2c95ac30eece357d414573762e26d5a66409d Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 21 Feb 2013 21:11:40 -0800 Subject: [PATCH] Add getProperty() with default value. --- .../properties/GuacamoleProperties.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/guacamole-ext/src/main/java/net/sourceforge/guacamole/properties/GuacamoleProperties.java b/guacamole-ext/src/main/java/net/sourceforge/guacamole/properties/GuacamoleProperties.java index d55e3e6be..f152a461d 100644 --- a/guacamole-ext/src/main/java/net/sourceforge/guacamole/properties/GuacamoleProperties.java +++ b/guacamole-ext/src/main/java/net/sourceforge/guacamole/properties/GuacamoleProperties.java @@ -156,6 +156,33 @@ public class GuacamoleProperties { } + /** + * Given a GuacamoleProperty, parses and returns the value set for that + * property in guacamole.properties, if any. If no value is found, the + * provided default value is returned. + * + * @param The type that the given property is parsed into. + * @param property The property to read from guacamole.properties. + * @param defaultValue The value to return if no value was given in + * guacamole.properties. + * @return The parsed value of the property as read from + * guacamole.properties, or the provided default value if no value + * was found. + * @throws GuacamoleException If an error occurs while parsing the value + * for the given property in + * guacamole.properties. + */ + public static Type getProperty(GuacamoleProperty property, + Type defaultValue) throws GuacamoleException { + + Type value = getProperty(property); + if (value == null) + return defaultValue; + + return value; + + } + /** * Given a GuacamoleProperty, parses and returns the value set for that * property in guacamole.properties. An exception is thrown if the value