Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8F8B79B5C for ; Fri, 2 Dec 2011 21:36:31 +0000 (UTC) Received: (qmail 67115 invoked by uid 500); 2 Dec 2011 21:36:31 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 67055 invoked by uid 500); 2 Dec 2011 21:36:31 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 67048 invoked by uid 99); 2 Dec 2011 21:36:31 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Dec 2011 21:36:31 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Dec 2011 21:36:29 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id F3F7023889C5 for ; Fri, 2 Dec 2011 21:36:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1209702 - /commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DataConfiguration.java Date: Fri, 02 Dec 2011 21:36:07 -0000 To: commits@commons.apache.org From: oheger@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111202213607.F3F7023889C5@eris.apache.org> Author: oheger Date: Fri Dec 2 21:36:07 2011 New Revision: 1209702 URL: http://svn.apache.org/viewvc?rev=1209702&view=rev Log: Java 1.5 compatibility: Javadocs, generics. Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DataConfiguration.java Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DataConfiguration.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DataConfiguration.java?rev=1209702&r1=1209701&r2=1209702&view=diff ============================================================================== --- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DataConfiguration.java (original) +++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DataConfiguration.java Fri Dec 2 21:36:07 2011 @@ -83,7 +83,7 @@ import org.apache.commons.lang.StringUti * org.apache.commons.configuration.format.date. * * @author Emmanuel Bourg - * @version $Revision$, $Date$ + * @version $Id$ * @since 1.1 */ public class DataConfiguration extends AbstractConfiguration implements Serializable @@ -103,7 +103,7 @@ public class DataConfiguration extends A protected Configuration configuration; /** - * Creates a new instance of DataConfiguration and sets the + * Creates a new instance of {@code DataConfiguration} and sets the * wrapped configuration. * * @param configuration the wrapped configuration @@ -128,6 +128,7 @@ public class DataConfiguration extends A return configuration.getProperty(key); } + @Override protected void addPropertyDirect(String key, Object obj) { if (configuration instanceof AbstractConfiguration) @@ -140,6 +141,7 @@ public class DataConfiguration extends A } } + @Override public void addProperty(String key, Object value) { getConfiguration().addProperty(key, value); @@ -155,17 +157,19 @@ public class DataConfiguration extends A return configuration.containsKey(key); } + @Override public void clearProperty(String key) { configuration.clearProperty(key); } + @Override public void setProperty(String key, Object value) { configuration.setProperty(key, value); } - public Iterator getKeys() + public Iterator getKeys() { return configuration.getKeys(); } @@ -187,9 +191,9 @@ public class DataConfiguration extends A * * @since 1.5 */ - public Object get(Class cls, String key) + public T get(Class cls, String key) { - Object value = get(cls, key, null); + T value = get(cls, key, null); if (value != null) { return value; @@ -209,7 +213,8 @@ public class DataConfiguration extends A * configuration key. If the key doesn't map to an existing object, the * default value is returned. * - * @param cls the target type of the value + * @param the target type of the value + * @param cls the target class of the value * @param key the key of the value * @param defaultValue the default value * @@ -219,7 +224,7 @@ public class DataConfiguration extends A * * @since 1.5 */ - public Object get(Class cls, String key, Object defaultValue) + public T get(Class cls, String key, T defaultValue) { Object value = resolveContainerStore(key); @@ -227,23 +232,14 @@ public class DataConfiguration extends A { return defaultValue; } + + if (Date.class.equals(cls) || Calendar.class.equals(cls)) + { + return convert(cls, key, interpolate(value), new String[] { getDefaultDateFormat() }); + } else { - try - { - if (Date.class.equals(cls) || Calendar.class.equals(cls)) - { - return PropertyConverter.to(cls, interpolate(value), new String[] {getDefaultDateFormat()}); - } - else - { - return PropertyConverter.to(cls, interpolate(value), null); - } - } - catch (ConversionException e) - { - throw new ConversionException('\'' + key + "' doesn't map to a " + cls, e); - } + return convert(cls, key, interpolate(value), null); } } @@ -251,7 +247,8 @@ public class DataConfiguration extends A * Get a list of typed objects associated with the given configuration key. * If the key doesn't map to an existing object, an empty list is returned. * - * @param cls the type expected for the elements of the list + * @param the type expected for the elements of the list + * @param cls the class expected for the elements of the list * @param key The configuration key. * @return The associated list if the key is found. * @@ -260,9 +257,9 @@ public class DataConfiguration extends A * * @since 1.5 */ - public List getList(Class cls, String key) + public List getList(Class cls, String key) { - return getList(cls, key, new ArrayList()); + return getList(cls, key, new ArrayList()); } /** @@ -270,7 +267,8 @@ public class DataConfiguration extends A * If the key doesn't map to an existing object, the default value is * returned. * - * @param cls the type expected for the elements of the list + * @param the type expected for the elements of the list + * @param cls the class expected for the elements of the list * @param key the configuration key. * @param defaultValue the default value. * @return The associated List. @@ -280,12 +278,12 @@ public class DataConfiguration extends A * * @since 1.5 */ - public List getList(Class cls, String key, List defaultValue) + public List getList(Class cls, String key, List defaultValue) { Object value = getProperty(key); - Class valueClass = value != null ? value.getClass() : null; + Class valueClass = value != null ? value.getClass() : null; - List list; + List list; if (value == null || (value instanceof String && StringUtils.isEmpty((String) value))) { @@ -294,7 +292,7 @@ public class DataConfiguration extends A } else { - list = new ArrayList(); + list = new ArrayList(); Object[] params = null; if (cls.equals(Date.class) || cls.equals(Calendar.class)) @@ -302,52 +300,44 @@ public class DataConfiguration extends A params = new Object[] {getDefaultDateFormat()}; } - try + if (valueClass.isArray()) { - if (valueClass.isArray()) - { - // get the class of the objects contained in the array - Class arrayType = valueClass.getComponentType(); - int length = Array.getLength(value); + // get the class of the objects contained in the array + Class arrayType = valueClass.getComponentType(); + int length = Array.getLength(value); - if (arrayType.equals(cls) - || (arrayType.isPrimitive() && cls.equals(ClassUtils.primitiveToWrapper(arrayType)))) - { - // the value is an array of the specified type, or an array - // of the primitive type derived from the specified type - for (int i = 0; i < length; i++) - { - list.add(Array.get(value, i)); - } - } - else + if (arrayType.equals(cls) + || (arrayType.isPrimitive() && cls.equals(ClassUtils.primitiveToWrapper(arrayType)))) + { + // the value is an array of the specified type, or an array + // of the primitive type derived from the specified type + for (int i = 0; i < length; i++) { - // attempt to convert the elements of the array - for (int i = 0; i < length; i++) - { - list.add(PropertyConverter.to(cls, interpolate(Array.get(value, i)), params)); - } + list.add(cls.cast(Array.get(value, i))); } } - else if (value instanceof Collection) + else { - Collection values = (Collection) value; - - Iterator it = values.iterator(); - while (it.hasNext()) + // attempt to convert the elements of the array + for (int i = 0; i < length; i++) { - list.add(PropertyConverter.to(cls, interpolate(it.next()), params)); + list.add(convert(cls, key, interpolate(Array.get(value, i)), params)); } } - else + } + else if (value instanceof Collection) + { + Collection values = (Collection) value; + + for (Object o : values) { - // attempt to convert a single value - list.add(PropertyConverter.to(cls, interpolate(value), params)); + list.add(convert(cls, key, interpolate(o), params)); } } - catch (ConversionException e) + else { - throw new ConversionException("'" + key + "' doesn't map to a list of " + cls, e); + // attempt to convert a single value + list.add(convert(cls, key, interpolate(value), params)); } } @@ -367,7 +357,7 @@ public class DataConfiguration extends A * * @since 1.5 */ - public Object getArray(Class cls, String key) + public Object getArray(Class cls, String key) { return getArray(cls, key, Array.newInstance(cls, 0)); } @@ -387,7 +377,7 @@ public class DataConfiguration extends A * * @since 1.5 */ - public Object getArray(Class cls, String key, Object defaultValue) + public Object getArray(Class cls, String key, Object defaultValue) { // check the type of the default value if (defaultValue != null @@ -406,7 +396,7 @@ public class DataConfiguration extends A return getPrimitiveArray(cls, key, defaultValue); } - List list = getList(cls, key); + List list = getList(cls, key); if (list.isEmpty()) { return defaultValue; @@ -431,10 +421,10 @@ public class DataConfiguration extends A * * @since 1.5 */ - private Object getPrimitiveArray(Class cls, String key, Object defaultValue) + private Object getPrimitiveArray(Class cls, String key, Object defaultValue) { Object value = getProperty(key); - Class valueClass = value != null ? value.getClass() : null; + Class valueClass = value != null ? value.getClass() : null; Object array; @@ -448,7 +438,7 @@ public class DataConfiguration extends A if (valueClass.isArray()) { // get the class of the objects contained in the array - Class arrayType = valueClass.getComponentType(); + Class arrayType = valueClass.getComponentType(); int length = Array.getLength(value); if (arrayType.equals(cls)) @@ -474,32 +464,31 @@ public class DataConfiguration extends A } else if (value instanceof Collection) { - Collection values = (Collection) value; + Collection values = (Collection) value; array = Array.newInstance(cls, values.size()); - Iterator it = values.iterator(); int i = 0; - while (it.hasNext()) + for (Object o : values) { - Array.set(array, i++, PropertyConverter.to(cls, interpolate(it.next()), null)); + // This is safe because PropertyConverter can handle + // conversion to wrapper classes correctly. + @SuppressWarnings("unchecked") + Object convertedValue = convert(ClassUtils.primitiveToWrapper(cls), key, interpolate(o), null); + Array.set(array, i++, convertedValue); } } else { - try - { - // attempt to convert a single value - Object convertedValue = PropertyConverter.to(cls, interpolate(value), null); - - // create an array of one element - array = Array.newInstance(cls, 1); - Array.set(array, 0, convertedValue); - } - catch (ConversionException e) - { - throw new ConversionException('\'' + key + "' doesn't map to an array of " + cls, e); - } + // attempt to convert a single value + // This is safe because PropertyConverter can handle + // conversion to wrapper classes correctly. + @SuppressWarnings("unchecked") + Object convertedValue = convert(ClassUtils.primitiveToWrapper(cls), key, interpolate(value), null); + + // create an array of one element + array = Array.newInstance(cls, 1); + Array.set(array, 0, convertedValue); } } @@ -517,9 +506,9 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of booleans. */ - public List getBooleanList(String key) + public List getBooleanList(String key) { - return getBooleanList(key, new ArrayList()); + return getBooleanList(key, new ArrayList()); } /** @@ -534,7 +523,7 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of booleans. */ - public List getBooleanList(String key, List defaultValue) + public List getBooleanList(String key, List defaultValue) { return getList(Boolean.class, key, defaultValue); } @@ -582,9 +571,9 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of bytes. */ - public List getByteList(String key) + public List getByteList(String key) { - return getByteList(key, new ArrayList()); + return getByteList(key, new ArrayList()); } /** @@ -599,7 +588,7 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of bytes. */ - public List getByteList(String key, List defaultValue) + public List getByteList(String key, List defaultValue) { return getList(Byte.class, key, defaultValue); } @@ -647,9 +636,9 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of shorts. */ - public List getShortList(String key) + public List getShortList(String key) { - return getShortList(key, new ArrayList()); + return getShortList(key, new ArrayList()); } /** @@ -664,7 +653,7 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of shorts. */ - public List getShortList(String key, List defaultValue) + public List getShortList(String key, List defaultValue) { return getList(Short.class, key, defaultValue); } @@ -713,9 +702,9 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of integers. */ - public List getIntegerList(String key) + public List getIntegerList(String key) { - return getIntegerList(key, new ArrayList()); + return getIntegerList(key, new ArrayList()); } /** @@ -730,7 +719,7 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of integers. */ - public List getIntegerList(String key, List defaultValue) + public List getIntegerList(String key, List defaultValue) { return getList(Integer.class, key, defaultValue); } @@ -778,9 +767,9 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of longs. */ - public List getLongList(String key) + public List getLongList(String key) { - return getLongList(key, new ArrayList()); + return getLongList(key, new ArrayList()); } /** @@ -795,7 +784,7 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of longs. */ - public List getLongList(String key, List defaultValue) + public List getLongList(String key, List defaultValue) { return getList(Long.class, key, defaultValue); } @@ -843,9 +832,9 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of floats. */ - public List getFloatList(String key) + public List getFloatList(String key) { - return getFloatList(key, new ArrayList()); + return getFloatList(key, new ArrayList()); } /** @@ -860,7 +849,7 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of floats. */ - public List getFloatList(String key, List defaultValue) + public List getFloatList(String key, List defaultValue) { return getList(Float.class, key, defaultValue); } @@ -909,9 +898,9 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of doubles. */ - public List getDoubleList(String key) + public List getDoubleList(String key) { - return getDoubleList(key, new ArrayList()); + return getDoubleList(key, new ArrayList()); } /** @@ -926,7 +915,7 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of doubles. */ - public List getDoubleList(String key, List defaultValue) + public List getDoubleList(String key, List defaultValue) { return getList(Double.class, key, defaultValue); } @@ -974,9 +963,9 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of BigIntegers. */ - public List getBigIntegerList(String key) + public List getBigIntegerList(String key) { - return getBigIntegerList(key, new ArrayList()); + return getBigIntegerList(key, new ArrayList()); } /** @@ -991,7 +980,7 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of BigIntegers. */ - public List getBigIntegerList(String key, List defaultValue) + public List getBigIntegerList(String key, List defaultValue) { return getList(BigInteger.class, key, defaultValue); } @@ -1039,9 +1028,9 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of BigDecimals. */ - public List getBigDecimalList(String key) + public List getBigDecimalList(String key) { - return getBigDecimalList(key, new ArrayList()); + return getBigDecimalList(key, new ArrayList()); } /** @@ -1056,7 +1045,7 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of BigDecimals. */ - public List getBigDecimalList(String key, List defaultValue) + public List getBigDecimalList(String key, List defaultValue) { return getList(BigDecimal.class, key, defaultValue); } @@ -1135,9 +1124,9 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of URLs. */ - public List getURLList(String key) + public List getURLList(String key) { - return getURLList(key, new ArrayList()); + return getURLList(key, new ArrayList()); } /** @@ -1152,7 +1141,7 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of URLs. */ - public List getURLList(String key, List defaultValue) + public List getURLList(String key, List defaultValue) { return getList(URL.class, key, defaultValue); } @@ -1286,23 +1275,9 @@ public class DataConfiguration extends A } } } - - /** - * Get a list of Dates associated with the given configuration key. - * If the property is a list of Strings, they will be parsed with the - * format defined by the user in the {@link #DATE_FORMAT_KEY} property, - * or if it's not defined with the {@link #DEFAULT_DATE_FORMAT} pattern. - * If the key doesn't map to an existing object an empty list is returned. - * - * @param key The configuration key. - * @return The associated Date list if the key is found. - * - * @throws ConversionException is thrown if the key maps to an - * object that is not a list of Dates. - */ - public List getDateList(String key) + public List getDateList(String key) { - return getDateList(key, new ArrayList()); + return getDateList(key, new ArrayList()); } /** @@ -1318,9 +1293,9 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of Dates. */ - public List getDateList(String key, String format) + public List getDateList(String key, String format) { - return getDateList(key, new ArrayList(), format); + return getDateList(key, new ArrayList(), format); } /** @@ -1338,7 +1313,7 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of Dates. */ - public List getDateList(String key, List defaultValue) + public List getDateList(String key, List defaultValue) { return getDateList(key, defaultValue, getDefaultDateFormat()); } @@ -1357,11 +1332,11 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of Dates. */ - public List getDateList(String key, List defaultValue, String format) + public List getDateList(String key, List defaultValue, String format) { Object value = getProperty(key); - List list; + List list; if (value == null || (value instanceof String && StringUtils.isEmpty((String) value))) { @@ -1369,36 +1344,28 @@ public class DataConfiguration extends A } else if (value.getClass().isArray()) { - list = new ArrayList(); + list = new ArrayList(); int length = Array.getLength(value); for (int i = 0; i < length; i++) { - list.add(PropertyConverter.toDate(interpolate(Array.get(value, i)), format)); + list.add(convert(Date.class, key, interpolate(Array.get(value, i)), new String[] { format })); } } else if (value instanceof Collection) { - Collection values = (Collection) value; - list = new ArrayList(); + Collection values = (Collection) value; + list = new ArrayList(); - Iterator it = values.iterator(); - while (it.hasNext()) + for (Object o : values) { - list.add(PropertyConverter.toDate(interpolate(it.next()), format)); + list.add(convert(Date.class, key, interpolate(o), new String[] { format })); } } else { - try - { - // attempt to convert a single value - list = new ArrayList(); - list.add(PropertyConverter.toDate(interpolate(value), format)); - } - catch (ConversionException e) - { - throw new ConversionException('\'' + key + "' doesn't map to a list of Dates", e); - } + // attempt to convert a single value + list = new ArrayList(); + list.add(convert(Date.class, key, interpolate(value), new String[] { format })); } return list; @@ -1475,14 +1442,14 @@ public class DataConfiguration extends A */ public Date[] getDateArray(String key, Date[] defaultValue, String format) { - List list = getDateList(key, format); + List list = getDateList(key, format); if (list.isEmpty()) { return defaultValue; } else { - return (Date[]) list.toArray(new Date[list.size()]); + return list.toArray(new Date[list.size()]); } } @@ -1599,9 +1566,9 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of Calendars. */ - public List getCalendarList(String key) + public List getCalendarList(String key) { - return getCalendarList(key, new ArrayList()); + return getCalendarList(key, new ArrayList()); } /** @@ -1617,9 +1584,9 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of Calendars. */ - public List getCalendarList(String key, String format) + public List getCalendarList(String key, String format) { - return getCalendarList(key, new ArrayList(), format); + return getCalendarList(key, new ArrayList(), format); } /** @@ -1637,7 +1604,7 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of Calendars. */ - public List getCalendarList(String key, List defaultValue) + public List getCalendarList(String key, List defaultValue) { return getCalendarList(key, defaultValue, getDefaultDateFormat()); } @@ -1656,11 +1623,11 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of Calendars. */ - public List getCalendarList(String key, List defaultValue, String format) + public List getCalendarList(String key, List defaultValue, String format) { Object value = getProperty(key); - List list; + List list; if (value == null || (value instanceof String && StringUtils.isEmpty((String) value))) { @@ -1668,36 +1635,28 @@ public class DataConfiguration extends A } else if (value.getClass().isArray()) { - list = new ArrayList(); + list = new ArrayList(); int length = Array.getLength(value); for (int i = 0; i < length; i++) { - list.add(PropertyConverter.toCalendar(interpolate(Array.get(value, i)), format)); + list.add(convert(Calendar.class, key, interpolate(Array.get(value, i)), new String[] { format })); } } else if (value instanceof Collection) { - Collection values = (Collection) value; - list = new ArrayList(); + Collection values = (Collection) value; + list = new ArrayList(); - Iterator it = values.iterator(); - while (it.hasNext()) + for (Object o : values) { - list.add(PropertyConverter.toCalendar(interpolate(it.next()), format)); + list.add(convert(Calendar.class, key, interpolate(o), new String[] { format })); } } else { - try - { - // attempt to convert a single value - list = new ArrayList(); - list.add(PropertyConverter.toCalendar(interpolate(value), format)); - } - catch (ConversionException e) - { - throw new ConversionException('\'' + key + "' doesn't map to a list of Calendars", e); - } + // attempt to convert a single value + list = new ArrayList(); + list.add(convert(Calendar.class, key, interpolate(value), new String[] { format })); } return list; @@ -1774,14 +1733,14 @@ public class DataConfiguration extends A */ public Calendar[] getCalendarArray(String key, Calendar[] defaultValue, String format) { - List list = getCalendarList(key, format); + List list = getCalendarList(key, format); if (list.isEmpty()) { return defaultValue; } else { - return (Calendar[]) list.toArray(new Calendar[list.size()]); + return list.toArray(new Calendar[list.size()]); } } @@ -1837,9 +1796,9 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of Locales. */ - public List getLocaleList(String key) + public List getLocaleList(String key) { - return getLocaleList(key, new ArrayList()); + return getLocaleList(key, new ArrayList()); } /** @@ -1854,7 +1813,7 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of Locales. */ - public List getLocaleList(String key, List defaultValue) + public List getLocaleList(String key, List defaultValue) { return getList(Locale.class, key, defaultValue); } @@ -1933,9 +1892,9 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of Colors. */ - public List getColorList(String key) + public List getColorList(String key) { - return getColorList(key, new ArrayList()); + return getColorList(key, new ArrayList()); } /** @@ -1950,7 +1909,7 @@ public class DataConfiguration extends A * @throws ConversionException is thrown if the key maps to an * object that is not a list of Colors. */ - public List getColorList(String key, List defaultValue) + public List getColorList(String key, List defaultValue) { return getList(Color.class, key, defaultValue); } @@ -1988,4 +1947,32 @@ public class DataConfiguration extends A return (Color[]) getArray(Color.class, key, defaultValue); } + /** + * Helper method for performing a type conversion using the + * {@code PropertyConverter} class. + * + * @param the target type of the conversion + * @param cls the target class of the conversion + * @param key the configuration key + * @param value the value to be converted + * @param params additional parameters + * @throws ConversionException if the value is not compatible with the + * requested type + */ + private static T convert(Class cls, String key, Object value, + Object[] params) + { + try + { + Object result = PropertyConverter.to(cls, value, params); + // Will not throw a ClassCastException because PropertyConverter + // would have thrown a ConversionException if conversion had failed. + return cls.cast(result); + } + catch (ConversionException e) + { + throw new ConversionException('\'' + key + "' doesn't map to a " + + cls, e); + } + } }