Author: bpoussin Date: 2010-12-10 04:11:19 +0100 (Fri, 10 Dec 2010) New Revision: 1971 Url: http://nuiton.org/repositories/revision/nuiton-utils/1971 Log: Evolution #1144: [ApplicationConfig] add getOptionAsList() method (change behavior, if no option for the key return empty list and not null) Modified: trunk/src/main/java/org/nuiton/util/ApplicationConfig.java Modified: trunk/src/main/java/org/nuiton/util/ApplicationConfig.java =================================================================== --- trunk/src/main/java/org/nuiton/util/ApplicationConfig.java 2010-12-10 02:17:23 UTC (rev 1970) +++ trunk/src/main/java/org/nuiton/util/ApplicationConfig.java 2010-12-10 03:11:19 UTC (rev 1971) @@ -1295,7 +1295,9 @@ * * example: * <li> convertOption(Boolean.class, "toto", "true,true", false) => false + * <li> convertOption(Boolean.class, "toto", null, false) => ? ConverterUtil dependant * <li> convertOption(Boolean.class, "toto", "true,true", true) => [true, true] + * <li> convertOption(Boolean.class, "toto", null, true) => [] * * @param clazz result type expected * @param key option key @@ -1316,9 +1318,8 @@ // if it's modified since last computation if (cacheItem == null || cacheItem.hash != hash) { if (asList) { - List<T> list = null; + List<T> list = new ArrayList<T>(); if (value != null) { - list = new ArrayList<T>(); String[] values = StringUtil.split(value, LIST_SEPARATOR); for (String valueString : values) { // prefer use our convertert method (auto-register more converters) @@ -1343,16 +1344,15 @@ } /** - * Help to convert value to list of object + * Help to convert value to list of object. If no option for this key + * empty List is returned finaly + * * @param key * @return */ public OptionList getOptionAsList(String key) { String value = getOption(key); - OptionList result = null; - if (value != null){ - result = new OptionList(this, key, value); - } + OptionList result = new OptionList(this, key, value); return result; }
participants (1)
-
bpoussin@users.nuiton.org