You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by eb...@apache.org on 2005/02/14 11:03:39 UTC
svn commit: r153757 - in jakarta/commons/proper/configuration/trunk/src:
java/org/apache/commons/configuration/DataConfiguration.java
test/org/apache/commons/configuration/TestDataConfiguration.java
test/org/apache/commons/configuration/TestPropertyConverter.java
Author: ebourg
Date: Mon Feb 14 02:03:35 2005
New Revision: 153757
URL: http://svn.apache.org/viewcvs?view=rev&rev=153757
Log:
Fixed getLongArray(), getFloatArray() and getDoubleArray() in DataConfiguration (Bug 33524)
Changed getXXXArray() and getXXXList() to return an empty array/list for empty values
Modified:
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DataConfiguration.java
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDataConfiguration.java
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertyConverter.java
Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DataConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DataConfiguration.java?view=diff&r1=153756&r2=153757
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DataConfiguration.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DataConfiguration.java Mon Feb 14 02:03:35 2005
@@ -30,6 +30,7 @@
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.lang.StringUtils;
/**
* Decorator providing additional getters for any Configuration. This extended
@@ -41,7 +42,7 @@
* version.</p>
*
* @author <a href="ebourg@apache.org">Emmanuel Bourg</a>
- * @version $Revision: 1.2 $, $Date: 2004/12/02 22:05:52 $
+ * @version $Revision: 1.2 $, $Date$
* @since 1.1
*/
public class DataConfiguration extends AbstractConfiguration
@@ -131,7 +132,7 @@
List list = null;
- if (value == null)
+ if (value == null || (value instanceof String && StringUtils.isEmpty((String) value)))
{
list = defaultValue;
}
@@ -207,7 +208,7 @@
boolean[] array;
- if (value == null)
+ if (value == null || (value instanceof String && StringUtils.isEmpty((String) value)))
{
array = defaultValue;
}
@@ -281,7 +282,7 @@
List list = null;
- if (value == null)
+ if (value == null || (value instanceof String && StringUtils.isEmpty((String) value)))
{
list = defaultValue;
}
@@ -356,7 +357,7 @@
byte[] array;
- if (value == null)
+ if (value == null || (value instanceof String && StringUtils.isEmpty((String) value)))
{
array = defaultValue;
}
@@ -430,7 +431,7 @@
List list = null;
- if (value == null)
+ if (value == null || (value instanceof String && StringUtils.isEmpty((String) value)))
{
list = defaultValue;
}
@@ -505,7 +506,7 @@
short[] array;
- if (value == null)
+ if (value == null || (value instanceof String && StringUtils.isEmpty((String) value)))
{
array = defaultValue;
}
@@ -580,7 +581,7 @@
List list = null;
- if (value == null)
+ if (value == null || (value instanceof String && StringUtils.isEmpty((String) value)))
{
list = defaultValue;
}
@@ -655,7 +656,7 @@
int[] array;
- if (value == null)
+ if (value == null || (value instanceof String && StringUtils.isEmpty((String) value)))
{
array = defaultValue;
}
@@ -729,7 +730,7 @@
List list = null;
- if (value == null)
+ if (value == null || (value instanceof String && StringUtils.isEmpty((String) value)))
{
list = defaultValue;
}
@@ -804,7 +805,7 @@
long[] array;
- if (value == null)
+ if (value == null || (value instanceof String && StringUtils.isEmpty((String) value)))
{
array = defaultValue;
}
@@ -825,7 +826,7 @@
Iterator it = values.iterator();
while (it.hasNext())
{
- array[i++] = PropertyConverter.toLong(it.next()).intValue();
+ array[i++] = PropertyConverter.toLong(it.next()).longValue();
}
}
else
@@ -834,7 +835,7 @@
{
// attempt to convert a single value
array = new long[1];
- array[0] = PropertyConverter.toLong(value).intValue();
+ array[0] = PropertyConverter.toLong(value).longValue();
}
catch (ConversionException e)
{
@@ -878,7 +879,7 @@
List list = null;
- if (value == null)
+ if (value == null || (value instanceof String && StringUtils.isEmpty((String) value)))
{
list = defaultValue;
}
@@ -953,7 +954,7 @@
float[] array;
- if (value == null)
+ if (value == null || (value instanceof String && StringUtils.isEmpty((String) value)))
{
array = defaultValue;
}
@@ -974,7 +975,7 @@
Iterator it = values.iterator();
while (it.hasNext())
{
- array[i++] = PropertyConverter.toFloat(it.next()).intValue();
+ array[i++] = PropertyConverter.toFloat(it.next()).floatValue();
}
}
else
@@ -983,7 +984,7 @@
{
// attempt to convert a single value
array = new float[1];
- array[0] = PropertyConverter.toFloat(value).intValue();
+ array[0] = PropertyConverter.toFloat(value).floatValue();
}
catch (ConversionException e)
{
@@ -1028,7 +1029,7 @@
List list = null;
- if (value == null)
+ if (value == null || (value instanceof String && StringUtils.isEmpty((String) value)))
{
list = defaultValue;
}
@@ -1103,7 +1104,7 @@
double[] array;
- if (value == null)
+ if (value == null || (value instanceof String && StringUtils.isEmpty((String) value)))
{
array = defaultValue;
}
@@ -1124,7 +1125,7 @@
Iterator it = values.iterator();
while (it.hasNext())
{
- array[i++] = PropertyConverter.toDouble(it.next()).intValue();
+ array[i++] = PropertyConverter.toDouble(it.next()).doubleValue();
}
}
else
@@ -1133,7 +1134,7 @@
{
// attempt to convert a single value
array = new double[1];
- array[0] = PropertyConverter.toDouble(value).intValue();
+ array[0] = PropertyConverter.toDouble(value).doubleValue();
}
catch (ConversionException e)
{
@@ -1177,7 +1178,7 @@
List list = null;
- if (value == null)
+ if (value == null || (value instanceof String && StringUtils.isEmpty((String) value)))
{
list = defaultValue;
}
@@ -1287,7 +1288,7 @@
List list = null;
- if (value == null)
+ if (value == null || (value instanceof String && StringUtils.isEmpty((String) value)))
{
list = defaultValue;
}
@@ -1444,7 +1445,7 @@
List list = null;
- if (value == null)
+ if (value == null || (value instanceof String && StringUtils.isEmpty((String) value)))
{
list = defaultValue;
}
@@ -1682,7 +1683,7 @@
List list = null;
- if (value == null)
+ if (value == null || (value instanceof String && StringUtils.isEmpty((String) value)))
{
list = defaultValue;
}
@@ -1974,7 +1975,7 @@
List list = null;
- if (value == null)
+ if (value == null || (value instanceof String && StringUtils.isEmpty((String) value)))
{
list = defaultValue;
}
@@ -2193,7 +2194,7 @@
List list = null;
- if (value == null)
+ if (value == null || (value instanceof String && StringUtils.isEmpty((String) value)))
{
list = defaultValue;
}
@@ -2350,7 +2351,7 @@
List list = null;
- if (value == null)
+ if (value == null || (value instanceof String && StringUtils.isEmpty((String) value)))
{
list = defaultValue;
}
Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDataConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDataConfiguration.java?view=diff&r1=153756&r2=153757
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDataConfiguration.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDataConfiguration.java Mon Feb 14 02:03:35 2005
@@ -34,7 +34,7 @@
/**
* @author Emmanuel Bourg
- * @version $Revision: 1.1 $, $Date: 2004/10/18 09:54:38 $
+ * @version $Revision: 1.1 $, $Date$
*/
public class TestDataConfiguration extends TestCase
{
@@ -44,6 +44,9 @@
{
conf = new DataConfiguration(new BaseConfiguration());
+ // empty value
+ conf.addProperty("empty", "");
+
// lists of boolean
conf.addProperty("boolean.list1", "true");
conf.addProperty("boolean.list1", "false");
@@ -289,6 +292,9 @@
// single boolean values
ArrayAssert.assertEquals(new boolean[] { true }, conf.getBooleanArray("boolean.string"));
ArrayAssert.assertEquals(new boolean[] { true }, conf.getBooleanArray("boolean.object"));
+
+ // empty array
+ ArrayAssert.assertEquals(new boolean[] { }, conf.getBooleanArray("empty"));
}
public void testGetBooleanList()
@@ -323,6 +329,9 @@
expected.add(Boolean.TRUE);
ListAssert.assertEquals(expected, conf.getBooleanList("boolean.string"));
ListAssert.assertEquals(expected, conf.getBooleanList("boolean.object"));
+
+ // empty list
+ ListAssert.assertEquals(new ArrayList(), conf.getBooleanList("empty"));
}
public void testGetByteArray()
@@ -354,6 +363,9 @@
// single byte values
ArrayAssert.assertEquals(new byte[] { 1 }, conf.getByteArray("byte.string"));
ArrayAssert.assertEquals(new byte[] { 1 }, conf.getByteArray("byte.object"));
+
+ // empty array
+ ArrayAssert.assertEquals(new byte[] { }, conf.getByteArray("empty"));
}
public void testGetByteList()
@@ -388,6 +400,9 @@
expected.add(new Byte("1"));
ListAssert.assertEquals(expected, conf.getByteList("byte.string"));
ListAssert.assertEquals(expected, conf.getByteList("byte.object"));
+
+ // empty list
+ ListAssert.assertEquals(new ArrayList(), conf.getByteList("empty"));
}
public void testGetShortArray()
@@ -419,6 +434,9 @@
// single byte values
ArrayAssert.assertEquals(new short[] { 1 }, conf.getShortArray("short.string"));
ArrayAssert.assertEquals(new short[] { 1 }, conf.getShortArray("short.object"));
+
+ // empty array
+ ArrayAssert.assertEquals(new short[] { }, conf.getShortArray("empty"));
}
public void testGetShortList()
@@ -453,6 +471,9 @@
expected.add(new Short("1"));
ListAssert.assertEquals(expected, conf.getShortList("short.string"));
ListAssert.assertEquals(expected, conf.getShortList("short.object"));
+
+ // empty list
+ ListAssert.assertEquals(new ArrayList(), conf.getShortList("empty"));
}
public void testGetIntegerArray()
@@ -484,6 +505,9 @@
// single int values
ArrayAssert.assertEquals(new int[] { 1 }, conf.getIntArray("integer.string"));
ArrayAssert.assertEquals(new int[] { 1 }, conf.getIntArray("integer.object"));
+
+ // empty array
+ ArrayAssert.assertEquals(new int[] { }, conf.getIntArray("empty"));
}
public void testGetIntegerList()
@@ -518,6 +542,9 @@
expected.add(new Integer("1"));
ListAssert.assertEquals(expected, conf.getIntegerList("integer.string"));
ListAssert.assertEquals(expected, conf.getIntegerList("integer.object"));
+
+ // empty list
+ ListAssert.assertEquals(new ArrayList(), conf.getIntegerList("empty"));
}
public void testGetLongArray()
@@ -549,6 +576,9 @@
// single long values
ArrayAssert.assertEquals(new long[] { 1 }, conf.getLongArray("long.string"));
ArrayAssert.assertEquals(new long[] { 1 }, conf.getLongArray("long.object"));
+
+ // empty array
+ ArrayAssert.assertEquals(new long[] { }, conf.getLongArray("empty"));
}
public void testGetLongList()
@@ -583,6 +613,9 @@
expected.add(new Long("1"));
ListAssert.assertEquals(expected, conf.getLongList("long.string"));
ListAssert.assertEquals(expected, conf.getLongList("long.object"));
+
+ // empty list
+ ListAssert.assertEquals(new ArrayList(), conf.getLongList("empty"));
}
public void testGetFloatArray()
@@ -614,6 +647,9 @@
// single float values
ArrayAssert.assertEquals(new float[] { 1 }, conf.getFloatArray("float.string"), 0);
ArrayAssert.assertEquals(new float[] { 1 }, conf.getFloatArray("float.object"), 0);
+
+ // empty array
+ ArrayAssert.assertEquals(new float[] { }, conf.getFloatArray("empty"), 0);
}
public void testGetFloatList()
@@ -648,6 +684,9 @@
expected.add(new Float("1"));
ListAssert.assertEquals(expected, conf.getFloatList("float.string"));
ListAssert.assertEquals(expected, conf.getFloatList("float.object"));
+
+ // empty list
+ ListAssert.assertEquals(new ArrayList(), conf.getFloatList("empty"));
}
public void testGetDoubleArray()
@@ -679,6 +718,9 @@
// single double values
ArrayAssert.assertEquals(new double[] { 1 }, conf.getDoubleArray("double.string"), 0);
ArrayAssert.assertEquals(new double[] { 1 }, conf.getDoubleArray("double.object"), 0);
+
+ // empty array
+ ArrayAssert.assertEquals(new double[] { }, conf.getDoubleArray("empty"), 0);
}
public void testGetDoubleList()
@@ -713,6 +755,9 @@
expected.add(new Double("1"));
ListAssert.assertEquals(expected, conf.getDoubleList("double.string"));
ListAssert.assertEquals(expected, conf.getDoubleList("double.object"));
+
+ // empty list
+ ListAssert.assertEquals(new ArrayList(), conf.getDoubleList("empty"));
}
public void testGetBigIntegerArray()
@@ -741,6 +786,9 @@
// single BigInteger values
ArrayAssert.assertEquals(new BigInteger[] { new BigInteger("1") }, conf.getBigIntegerArray("biginteger.string"));
ArrayAssert.assertEquals(new BigInteger[] { new BigInteger("1") }, conf.getBigIntegerArray("biginteger.object"));
+
+ // empty array
+ ArrayAssert.assertEquals(new BigInteger[] { }, conf.getBigIntegerArray("empty"));
}
public void testGetBigIntegerList()
@@ -772,6 +820,9 @@
expected.add(new BigInteger("1"));
ListAssert.assertEquals(expected, conf.getBigIntegerList("biginteger.string"));
ListAssert.assertEquals(expected, conf.getBigIntegerList("biginteger.object"));
+
+ // empty list
+ ListAssert.assertEquals(new ArrayList(), conf.getBigIntegerList("empty"));
}
public void testGetBigDecimalArray()
@@ -800,6 +851,9 @@
// single BigDecimal values
ArrayAssert.assertEquals(new BigDecimal[] { new BigDecimal("1") }, conf.getBigDecimalArray("bigdecimal.string"));
ArrayAssert.assertEquals(new BigDecimal[] { new BigDecimal("1") }, conf.getBigDecimalArray("bigdecimal.object"));
+
+ // empty array
+ ArrayAssert.assertEquals(new BigDecimal[] { }, conf.getBigDecimalArray("empty"));
}
public void testGetBigDecimalList()
@@ -831,6 +885,9 @@
expected.add(new BigDecimal("1"));
ListAssert.assertEquals(expected, conf.getBigDecimalList("bigdecimal.string"));
ListAssert.assertEquals(expected, conf.getBigDecimalList("bigdecimal.object"));
+
+ // empty list
+ ListAssert.assertEquals(new ArrayList(), conf.getBigDecimalList("empty"));
}
public void testGetURL() throws Exception
@@ -874,6 +931,9 @@
// single URL values
ArrayAssert.assertEquals(new URL[] { new URL("http://jakarta.apache.org") }, conf.getURLArray("url.string"));
ArrayAssert.assertEquals(new URL[] { new URL("http://jakarta.apache.org") }, conf.getURLArray("url.object"));
+
+ // empty array
+ ArrayAssert.assertEquals(new URL[] { }, conf.getURLArray("empty"));
}
public void testGetURLList() throws Exception
@@ -905,6 +965,9 @@
expected.add(new URL("http://www.apache.org"));
ListAssert.assertEquals(expected, conf.getURLList("url.string"));
ListAssert.assertEquals(expected, conf.getURLList("url.object"));
+
+ // empty list
+ ListAssert.assertEquals(new ArrayList(), conf.getURLList("empty"));
}
public void testGetLocale()
@@ -965,6 +1028,9 @@
// single Locale values
ArrayAssert.assertEquals(new Locale[] { Locale.FRENCH }, conf.getLocaleArray("locale.string"));
ArrayAssert.assertEquals(new Locale[] { Locale.FRENCH }, conf.getLocaleArray("locale.object"));
+
+ // empty array
+ ArrayAssert.assertEquals(new Locale[] { }, conf.getLocaleArray("empty"));
}
public void testGetLocaleList() throws Exception
@@ -996,6 +1062,9 @@
expected.add(Locale.FRENCH);
ListAssert.assertEquals(expected, conf.getLocaleList("locale.string"));
ListAssert.assertEquals(expected, conf.getLocaleList("locale.object"));
+
+ // empty list
+ ListAssert.assertEquals(new ArrayList(), conf.getLocaleList("empty"));
}
public void testGetColor()
@@ -1044,6 +1113,9 @@
// single Color values
ArrayAssert.assertEquals(new Color[] { Color.red }, conf.getColorArray("color.string"));
ArrayAssert.assertEquals(new Color[] { Color.red }, conf.getColorArray("color.object"));
+
+ // empty array
+ ArrayAssert.assertEquals(new Color[] { }, conf.getColorArray("empty"));
}
public void testGetColorList() throws Exception
@@ -1075,6 +1147,9 @@
expected.add(Color.red);
ListAssert.assertEquals(expected, conf.getColorList("color.string"));
ListAssert.assertEquals(expected, conf.getColorList("color.object"));
+
+ // empty list
+ ListAssert.assertEquals(new ArrayList(), conf.getColorList("empty"));
}
public void testGetDate() throws Exception
@@ -1130,6 +1205,9 @@
// single Date values
ArrayAssert.assertEquals(new Date[] { date1 }, conf.getDateArray("date.string"));
ArrayAssert.assertEquals(new Date[] { date1 }, conf.getDateArray("date.object"));
+
+ // empty array
+ ArrayAssert.assertEquals(new Date[] { }, conf.getDateArray("empty"));
}
public void testGetDateList() throws Exception
@@ -1168,6 +1246,9 @@
expected.add(date1);
ListAssert.assertEquals(expected, conf.getDateList("date.string"));
ListAssert.assertEquals(expected, conf.getDateList("date.object"));
+
+ // empty list
+ ListAssert.assertEquals(new ArrayList(), conf.getDateList("empty"));
}
public void testGetCalendar() throws Exception
@@ -1230,6 +1311,9 @@
// single Calendar values
ArrayAssert.assertEquals(new Calendar[] { calendar1 }, conf.getCalendarArray("calendar.string"));
ArrayAssert.assertEquals(new Calendar[] { calendar1 }, conf.getCalendarArray("calendar.object"));
+
+ // empty array
+ ArrayAssert.assertEquals(new Calendar[] { }, conf.getCalendarArray("empty"));
}
public void testGetCalendarList() throws Exception
@@ -1272,6 +1356,9 @@
expected.add(calendar1);
ListAssert.assertEquals(expected, conf.getCalendarList("date.string"));
ListAssert.assertEquals(expected, conf.getCalendarList("date.object"));
+
+ // empty list
+ ListAssert.assertEquals(new ArrayList(), conf.getCalendarList("empty"));
}
public void testConversionException()
Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertyConverter.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertyConverter.java?view=diff&r1=153756&r2=153757
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertyConverter.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertyConverter.java Mon Feb 14 02:03:35 2005
@@ -7,7 +7,7 @@
/**
* @author Emmanuel Bourg
- * @version $Revision: 1.1 $, $Date: 2004/12/14 17:03:51 $
+ * @version $Revision: 1.1 $, $Date$
*/
public class TestPropertyConverter extends TestCase
{
@@ -69,5 +69,10 @@
assertEquals("1st element", new Integer(1), it.next());
assertEquals("2nd element", new Integer(2), it.next());
assertEquals("3rd element", new Integer(3), it.next());
+ }
+
+ public void testToLong()
+ {
+ assertEquals("81008931800 to long", 81008931800L, PropertyConverter.toLong("81008931800").longValue());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org