Add convenience method to return multi-value string properties as List<String>
GENERAL
TESTING
GENERAL
TESTING
Description
Currently ServerConfigurationService has a method called getStrings() to read in multi-value string properies as String[]. It would be handy to have the option to return as List<String> instead, with an empty list returned instead of null if the property is not found. This will reduce the need to write null checking and list conversion code when working with multi-value Sakai properties.
Attached is a simple implementation built on top of the existing getStrings() method.
Attachments
1
20 Feb 2013, 11:32 AM
Activity
Show:
Paul Lukasewych February 20, 2013 at 1:49 PM
Thanks, I didn't know about ArrayUtils. I can pretty much replicate this functionality with a one-liner now.
Aaron Zeckoski February 20, 2013 at 12:59 PM
We don't really want to duplicate methods in APIs. It's a bad practice according to industry standards and the array method already provides this. If you want to patch the public <T> T getConfig(String name, T defaultValue) to convert the arrays to lists then I think that could be useful but since it is so easy to turn an array into a list using a single ArrayUtils call, I don't really see much point.
Matthew Jones February 20, 2013 at 11:54 AM
In the olden days of java, the preference was to return the array because you knew what return type you were getting (a huge benefit). Nowadays I also personally prefer using Collections whenever possible to avoid null checks and predictable results in loops. However I don't think having an essentially duplicate method which won't be in until 2.10 really adds much? I think if this gets in the other method should be depreciated.
Currently ServerConfigurationService has a method called getStrings() to read in multi-value string properies as String[]. It would be handy to have the option to return as List<String> instead, with an empty list returned instead of null if the property is not found. This will reduce the need to write null checking and list conversion code when working with multi-value Sakai properties.
Attached is a simple implementation built on top of the existing getStrings() method.