Author: oheger
Date: Wed Jan 23 13:34:47 2008
New Revision: 614689
URL: http://svn.apache.org/viewvc?rev=614689&view=rev
Log:
Fixed Java 1.5 related warnings; improved type safety
Modified:
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/DataConfiguration.java
Modified:
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/DataConfiguration.java
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/DataConfiguration.java?rev=614689&r1=614688&r2=614689&view=diff
==============================================================================
---
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/DataConfiguration.java
(original)
+++
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/DataConfiguration.java
Wed Jan 23 13:34:47 2008
@@ -177,9 +177,9 @@
*
* @since 1.5
*/
- public Object get(Class cls, String key)
+ public <T> T get(Class<T> cls, String key)
{
- Object value = get(cls, key, null);
+ T value = get(cls, key, null);
if (value != null)
{
return value;
@@ -209,7 +209,7 @@
*
* @since 1.5
*/
- public Object get(Class cls, String key, Object defaultValue)
+ public <T> T get(Class<T> cls, String key, T defaultValue)
{
Object value = resolveContainerStore(key);
@@ -250,9 +250,9 @@
*
* @since 1.5
*/
- public List getList(Class cls, String key)
+ public <T> List<T> getList(Class<T> cls, String key)
{
- return getList(cls, key, new ArrayList());
+ return getList(cls, key, new ArrayList<T>());
}
/**
@@ -270,12 +270,12 @@
*
* @since 1.5
*/
- public List getList(Class cls, String key, List defaultValue)
+ public <T> List<T> getList(Class<T> cls, String key, List<T> defaultValue)
{
Object value = getProperty(key);
- Class valueClass = value != null ? value.getClass() : null;
+ Class<?> valueClass = value != null ? value.getClass() : null;
- List list;
+ List<T> list;
if (value == null || (value instanceof String &&
StringUtils.isEmpty((String) value)))
{
@@ -284,7 +284,7 @@
}
else
{
- list = new ArrayList();
+ list = new ArrayList<T>();
Object[] params = null;
if (cls.equals(Date.class) || cls.equals(Calendar.class))
@@ -297,7 +297,7 @@
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)
@@ -307,7 +307,7 @@
// of the primitive type derived from the specified
type
for (int i = 0; i < length; i++)
{
- list.add(Array.get(value, i));
+ list.add(cls.cast(Array.get(value, i)));
}
}
else
@@ -321,12 +321,11 @@
}
else if (value instanceof Collection)
{
- Collection values = (Collection) value;
+ Collection<?> values = (Collection<?>) value;
- Iterator it = values.iterator();
- while (it.hasNext())
+ for (Object o : values)
{
- list.add(PropertyConverter.to(cls,
interpolate(it.next()), params));
+ list.add(PropertyConverter.to(cls, interpolate(o),
params));
}
}
else
@@ -357,7 +356,7 @@
*
* @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));
}
@@ -377,7 +376,7 @@
*
* @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
@@ -396,7 +395,7 @@
return getPrimitiveArray(cls, key, defaultValue);
}
- List list = getList(cls, key);
+ List<?> list = getList(cls, key);
if (list.isEmpty())
{
return defaultValue;
@@ -421,10 +420,11 @@
*
* @since 1.5
*/
- private Object getPrimitiveArray(Class cls, String key, Object
defaultValue)
+ @SuppressWarnings("unchecked")
+ 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;
@@ -438,7 +438,7 @@
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))
@@ -464,15 +464,14 @@
}
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(ClassUtils.primitiveToWrapper(cls),
interpolate(it.next()), null));
+ Array.set(array, i++,
PropertyConverter.to(ClassUtils.primitiveToWrapper(cls), interpolate(o), null));
}
}
else
@@ -507,9 +506,9 @@
* @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<Boolean> getBooleanList(String key)
{
- return getBooleanList(key, new ArrayList());
+ return getBooleanList(key, new ArrayList<Boolean>());
}
/**
@@ -524,7 +523,7 @@
* @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<Boolean> getBooleanList(String key, List<Boolean> defaultValue)
{
return getList(Boolean.class, key, defaultValue);
}
@@ -572,9 +571,9 @@
* @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<Byte> getByteList(String key)
{
- return getByteList(key, new ArrayList());
+ return getByteList(key, new ArrayList<Byte>());
}
/**
@@ -589,7 +588,7 @@
* @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<Byte> getByteList(String key, List<Byte> defaultValue)
{
return getList(Byte.class, key, defaultValue);
}
@@ -637,9 +636,9 @@
* @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<Short> getShortList(String key)
{
- return getShortList(key, new ArrayList());
+ return getShortList(key, new ArrayList<Short>());
}
/**
@@ -654,7 +653,7 @@
* @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<Short> getShortList(String key, List<Short> defaultValue)
{
return getList(Short.class, key, defaultValue);
}
@@ -703,9 +702,9 @@
* @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<Integer> getIntegerList(String key)
{
- return getIntegerList(key, new ArrayList());
+ return getIntegerList(key, new ArrayList<Integer>());
}
/**
@@ -720,7 +719,7 @@
* @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<Integer> getIntegerList(String key, List<Integer> defaultValue)
{
return getList(Integer.class, key, defaultValue);
}
@@ -768,9 +767,9 @@
* @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<Long> getLongList(String key)
{
- return getLongList(key, new ArrayList());
+ return getLongList(key, new ArrayList<Long>());
}
/**
@@ -785,7 +784,7 @@
* @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<Long> getLongList(String key, List<Long> defaultValue)
{
return getList(Long.class, key, defaultValue);
}
@@ -833,9 +832,9 @@
* @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<Float> getFloatList(String key)
{
- return getFloatList(key, new ArrayList());
+ return getFloatList(key, new ArrayList<Float>());
}
/**
@@ -850,7 +849,7 @@
* @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<Float> getFloatList(String key, List<Float> defaultValue)
{
return getList(Float.class, key, defaultValue);
}
@@ -899,9 +898,9 @@
* @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<Double> getDoubleList(String key)
{
- return getDoubleList(key, new ArrayList());
+ return getDoubleList(key, new ArrayList<Double>());
}
/**
@@ -916,7 +915,7 @@
* @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<Double> getDoubleList(String key, List<Double> defaultValue)
{
return getList(Double.class, key, defaultValue);
}
@@ -964,9 +963,9 @@
* @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<BigInteger> getBigIntegerList(String key)
{
- return getBigIntegerList(key, new ArrayList());
+ return getBigIntegerList(key, new ArrayList<BigInteger>());
}
/**
@@ -981,7 +980,7 @@
* @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<BigInteger> getBigIntegerList(String key, List<BigInteger>
defaultValue)
{
return getList(BigInteger.class, key, defaultValue);
}
@@ -1029,9 +1028,9 @@
* @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<BigDecimal> getBigDecimalList(String key)
{
- return getBigDecimalList(key, new ArrayList());
+ return getBigDecimalList(key, new ArrayList<BigDecimal>());
}
/**
@@ -1046,7 +1045,7 @@
* @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<BigDecimal> getBigDecimalList(String key, List<BigDecimal>
defaultValue)
{
return getList(BigDecimal.class, key, defaultValue);
}
@@ -1125,9 +1124,9 @@
* @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<URL> getURLList(String key)
{
- return getURLList(key, new ArrayList());
+ return getURLList(key, new ArrayList<URL>());
}
/**
@@ -1142,7 +1141,7 @@
* @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<URL> getURLList(String key, List<URL> defaultValue)
{
return getList(URL.class, key, defaultValue);
}
@@ -1290,9 +1289,9 @@
* @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<Date> getDateList(String key)
{
- return getDateList(key, new ArrayList());
+ return getDateList(key, new ArrayList<Date>());
}
/**
@@ -1308,9 +1307,9 @@
* @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<Date> getDateList(String key, String format)
{
- return getDateList(key, new ArrayList(), format);
+ return getDateList(key, new ArrayList<Date>(), format);
}
/**
@@ -1328,7 +1327,7 @@
* @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<Date> getDateList(String key, List<Date> defaultValue)
{
return getDateList(key, defaultValue, getDefaultDateFormat());
}
@@ -1347,11 +1346,11 @@
* @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<Date> getDateList(String key, List<Date> defaultValue, String
format)
{
Object value = getProperty(key);
- List list;
+ List<Date> list;
if (value == null || (value instanceof String &&
StringUtils.isEmpty((String) value)))
{
@@ -1359,7 +1358,7 @@
}
else if (value.getClass().isArray())
{
- list = new ArrayList();
+ list = new ArrayList<Date>();
int length = Array.getLength(value);
for (int i = 0; i < length; i++)
{
@@ -1368,13 +1367,12 @@
}
else if (value instanceof Collection)
{
- Collection values = (Collection) value;
- list = new ArrayList();
+ Collection<?> values = (Collection<?>) value;
+ list = new ArrayList<Date>();
- Iterator it = values.iterator();
- while (it.hasNext())
+ for (Object o : values)
{
- list.add(PropertyConverter.toDate(interpolate(it.next()),
format));
+ list.add(PropertyConverter.toDate(interpolate(o), format));
}
}
else
@@ -1382,7 +1380,7 @@
try
{
// attempt to convert a single value
- list = new ArrayList();
+ list = new ArrayList<Date>();
list.add(PropertyConverter.toDate(interpolate(value), format));
}
catch (ConversionException e)
@@ -1465,14 +1463,14 @@
*/
public Date[] getDateArray(String key, Date[] defaultValue, String format)
{
- List list = getDateList(key, format);
+ List<Date> 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()]);
}
}
@@ -1589,9 +1587,9 @@
* @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<Calendar> getCalendarList(String key)
{
- return getCalendarList(key, new ArrayList());
+ return getCalendarList(key, new ArrayList<Calendar>());
}
/**
@@ -1607,9 +1605,9 @@
* @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<Calendar> getCalendarList(String key, String format)
{
- return getCalendarList(key, new ArrayList(), format);
+ return getCalendarList(key, new ArrayList<Calendar>(), format);
}
/**
@@ -1627,7 +1625,7 @@
* @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<Calendar> getCalendarList(String key, List<Calendar>
defaultValue)
{
return getCalendarList(key, defaultValue, getDefaultDateFormat());
}
@@ -1646,11 +1644,11 @@
* @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<Calendar> getCalendarList(String key, List<Calendar>
defaultValue, String format)
{
Object value = getProperty(key);
- List list;
+ List<Calendar> list;
if (value == null || (value instanceof String &&
StringUtils.isEmpty((String) value)))
{
@@ -1658,7 +1656,7 @@
}
else if (value.getClass().isArray())
{
- list = new ArrayList();
+ list = new ArrayList<Calendar>();
int length = Array.getLength(value);
for (int i = 0; i < length; i++)
{
@@ -1667,13 +1665,12 @@
}
else if (value instanceof Collection)
{
- Collection values = (Collection) value;
- list = new ArrayList();
+ Collection<?> values = (Collection<?>) value;
+ list = new ArrayList<Calendar>();
- Iterator it = values.iterator();
- while (it.hasNext())
+ for (Object o : values)
{
- list.add(PropertyConverter.toCalendar(interpolate(it.next()),
format));
+ list.add(PropertyConverter.toCalendar(interpolate(o), format));
}
}
else
@@ -1681,7 +1678,7 @@
try
{
// attempt to convert a single value
- list = new ArrayList();
+ list = new ArrayList<Calendar>();
list.add(PropertyConverter.toCalendar(interpolate(value),
format));
}
catch (ConversionException e)
@@ -1764,14 +1761,14 @@
*/
public Calendar[] getCalendarArray(String key, Calendar[] defaultValue,
String format)
{
- List list = getCalendarList(key, format);
+ List<Calendar> 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()]);
}
}
@@ -1827,9 +1824,9 @@
* @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<Locale> getLocaleList(String key)
{
- return getLocaleList(key, new ArrayList());
+ return getLocaleList(key, new ArrayList<Locale>());
}
/**
@@ -1844,7 +1841,7 @@
* @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<Locale> getLocaleList(String key, List<Locale> defaultValue)
{
return getList(Locale.class, key, defaultValue);
}
@@ -1923,9 +1920,9 @@
* @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<Color> getColorList(String key)
{
- return getColorList(key, new ArrayList());
+ return getColorList(key, new ArrayList<Color>());
}
/**
@@ -1940,7 +1937,7 @@
* @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<Color> getColorList(String key, List<Color> defaultValue)
{
return getList(Color.class, key, defaultValue);
}