Author: oheger
Date: Sat Oct 26 19:43:39 2013
New Revision: 1536026
URL: http://svn.apache.org/r1536026
Log:
Generified LazyDynaBean.
Modified:
commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/LazyDynaBean.java
commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/LazyDynaBeanTestCase.java
Modified:
commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/LazyDynaBean.java
URL:
http://svn.apache.org/viewvc/commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/LazyDynaBean.java?rev=1536026&r1=1536025&r2=1536026&view=diff
==============================================================================
---
commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/LazyDynaBean.java
(original)
+++
commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/LazyDynaBean.java
Sat Oct 26 19:43:39 2013
@@ -16,15 +16,16 @@
*/
package org.apache.commons.beanutils;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Date;
+import java.io.Serializable;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
-import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -141,10 +142,10 @@ public class LazyDynaBean implements Dyn
* The <code>MutableDynaClass</code> "base class" that this DynaBean
* is associated with.
*/
- protected Map values;
+ protected Map<String, Object> values;
/** Map decorator for this DynaBean */
- private transient Map mapDecorator;
+ private transient Map<Object, Object> mapDecorator;
/**
* The <code>MutableDynaClass</code> "base class" that this DynaBean
@@ -202,7 +203,7 @@ public class LazyDynaBean implements Dyn
*
* @return a Map representation of this DynaBean
*/
- public Map getMap() {
+ public Map<Object, Object> getMap() {
// cache the Map
if (mapDecorator == null) {
mapDecorator = new DynaBeanMapDecorator(this);
@@ -229,11 +230,11 @@ public class LazyDynaBean implements Dyn
}
if (value instanceof Map) {
- return ((Map)value).size();
+ return ((Map<?, ?>)value).size();
}
if (value instanceof List) {
- return ((List)value).size();
+ return ((List<?>)value).size();
}
if ((value.getClass().isArray())) {
@@ -269,7 +270,7 @@ public class LazyDynaBean implements Dyn
}
if (value instanceof Map) {
- return (((Map) value).containsKey(key));
+ return (((Map<?, ?>) value).containsKey(key));
}
return false;
@@ -353,7 +354,7 @@ public class LazyDynaBean implements Dyn
if (indexedProperty.getClass().isArray()) {
return Array.get(indexedProperty, index);
} else if (indexedProperty instanceof List) {
- return ((List)indexedProperty).get(index);
+ return ((List<?>)indexedProperty).get(index);
} else {
throw new IllegalArgumentException
("Non-indexed property for '" + name + "[" + index + "]' "
@@ -394,7 +395,7 @@ public class LazyDynaBean implements Dyn
// Get the value from the Map
if (mappedProperty instanceof Map) {
- return (((Map) mappedProperty).get(key));
+ return (((Map<?, ?>) mappedProperty).get(key));
} else {
throw new IllegalArgumentException
("Non-mapped property for '" + name + "(" + key + ")'"
@@ -437,7 +438,7 @@ public class LazyDynaBean implements Dyn
}
if (value instanceof Map) {
- ((Map) value).remove(key);
+ ((Map<?, ?>) value).remove(key);
} else {
throw new IllegalArgumentException
("Non-mapped property for '" + name + "(" + key + ")'"
@@ -536,7 +537,10 @@ public class LazyDynaBean implements Dyn
if (indexedProperty.getClass().isArray()) {
Array.set(indexedProperty, index, value);
} else if (indexedProperty instanceof List) {
- ((List)indexedProperty).set(index, value);
+ @SuppressWarnings("unchecked")
+ // Indexed properties are stored in a List<Object>
+ List<Object> values = (List<Object>) indexedProperty;
+ values.set(index, value);
} else {
throw new IllegalArgumentException
("Non-indexed property for '" + name + "[" + index + "]' "
@@ -577,7 +581,10 @@ public class LazyDynaBean implements Dyn
}
// Set the value in the Map
- ((Map)mappedProperty).put(key, value);
+ @SuppressWarnings("unchecked")
+ // mapped properties are stored in a Map<String, Object>
+ Map<String, Object> valuesMap = (Map<String, Object>) mappedProperty;
+ valuesMap.put(key, value);
}
@@ -596,9 +603,11 @@ public class LazyDynaBean implements Dyn
// Grow a List to the appropriate size
if (indexedProperty instanceof List) {
- List list = (List)indexedProperty;
+ @SuppressWarnings("unchecked")
+ // Indexed properties are stored as List<Object>
+ List<Object> list = (List<Object>)indexedProperty;
while (index >= list.size()) {
- Class contentType =
getDynaClass().getDynaProperty(name).getContentType();
+ Class<?> contentType =
getDynaClass().getDynaProperty(name).getContentType();
Object value = null;
if (contentType != null) {
value = createProperty(name+"["+list.size()+"]",
contentType);
@@ -613,7 +622,7 @@ public class LazyDynaBean implements Dyn
int length = Array.getLength(indexedProperty);
if (index >= length) {
- Class componentType =
indexedProperty.getClass().getComponentType();
+ Class<?> componentType =
indexedProperty.getClass().getComponentType();
Object newArray = Array.newInstance(componentType, (index +
1));
System.arraycopy(indexedProperty, 0, newArray, 0, length);
indexedProperty = newArray;
@@ -635,7 +644,7 @@ public class LazyDynaBean implements Dyn
* @param type The class of the property
* @return The new value
*/
- protected Object createProperty(String name, Class type) {
+ protected Object createProperty(String name, Class<?> type) {
if (type == null) {
return null;
}
@@ -671,7 +680,7 @@ public class LazyDynaBean implements Dyn
* @param type The class of the property
* @return The new value
*/
- protected Object createIndexedProperty(String name, Class type) {
+ protected Object createIndexedProperty(String name, Class<?> type) {
// Create the indexed object
Object indexedProperty = null;
@@ -713,7 +722,7 @@ public class LazyDynaBean implements Dyn
* @param type The class of the property
* @return The new value
*/
- protected Object createMappedProperty(String name, Class type) {
+ protected Object createMappedProperty(String name, Class<?> type) {
// Create the mapped object
Object mappedProperty = null;
@@ -751,7 +760,7 @@ public class LazyDynaBean implements Dyn
* @param type The class of the property
* @return The new value
*/
- protected Object createDynaBeanProperty(String name, Class type) {
+ protected Object createDynaBeanProperty(String name, Class<?> type) {
try {
return type.newInstance();
}
@@ -770,7 +779,7 @@ public class LazyDynaBean implements Dyn
* @param type The class of the property
* @return The new value
*/
- protected Object createPrimitiveProperty(String name, Class type) {
+ protected Object createPrimitiveProperty(String name, Class<?> type) {
if (type == Boolean.TYPE) {
return Boolean.FALSE;
@@ -800,7 +809,7 @@ public class LazyDynaBean implements Dyn
* @param type The class of the property
* @return The new value
*/
- protected Object createNumberProperty(String name, Class type) {
+ protected Object createNumberProperty(String name, Class<?> type) {
return null;
@@ -812,7 +821,7 @@ public class LazyDynaBean implements Dyn
* @param type The class of the property
* @return The new value
*/
- protected Object createOtherProperty(String name, Class type) {
+ protected Object createOtherProperty(String name, Class<?> type) {
if (type == Object.class ||
type == String.class ||
@@ -839,28 +848,28 @@ public class LazyDynaBean implements Dyn
* <p>Creates a new <code>ArrayList</code> for an 'indexed' property
* which doesn't exist.</p>
*
- * <p>This method shouls be overriden if an alternative <code>List</code>
+ * <p>This method should be overridden if an alternative <code>List</code>
* or <code>Array</code> implementation is required for 'indexed'
properties.</p>
*
* @param name Name of the 'indexed property.
* @return The default value for an indexed property (java.util.ArrayList)
*/
protected Object defaultIndexedProperty(String name) {
- return new ArrayList();
+ return new ArrayList<Object>();
}
/**
* <p>Creates a new <code>HashMap</code> for a 'mapped' property
* which doesn't exist.</p>
*
- * <p>This method can be overriden if an alternative <code>Map</code>
+ * <p>This method can be overridden if an alternative <code>Map</code>
* implementation is required for 'mapped' properties.</p>
*
* @param name Name of the 'mapped property.
* @return The default value for a mapped property (java.util.HashMap)
*/
- protected Map defaultMappedProperty(String name) {
- return new HashMap();
+ protected Map<String, Object> defaultMappedProperty(String name) {
+ return new HashMap<String, Object>();
}
/**
@@ -893,7 +902,7 @@ public class LazyDynaBean implements Dyn
* @return <code>true<code> if the source class is assignable to the
* destination class, otherwise <code>false</code>
*/
- protected boolean isAssignable(Class dest, Class source) {
+ protected boolean isAssignable(Class<?> dest, Class<?> source) {
if (dest.isAssignableFrom(source) ||
((dest == Boolean.TYPE) && (source == Boolean.class)) ||
@@ -915,8 +924,8 @@ public class LazyDynaBean implements Dyn
* <p>Creates a new instance of the <code>Map</code>.</p>
* @return a new Map instance
*/
- protected Map newMap() {
- return new HashMap();
+ protected Map<String, Object> newMap() {
+ return new HashMap<String, Object>();
}
/**
Modified:
commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/LazyDynaBeanTestCase.java
URL:
http://svn.apache.org/viewvc/commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/LazyDynaBeanTestCase.java?rev=1536026&r1=1536025&r2=1536026&view=diff
==============================================================================
---
commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/LazyDynaBeanTestCase.java
(original)
+++
commons/proper/beanutils/branches/java5/src/test/java/org/apache/commons/beanutils/LazyDynaBeanTestCase.java
Sat Oct 26 19:43:39 2013
@@ -16,13 +16,14 @@
*/
package org.apache.commons.beanutils;
-import java.util.HashMap;
-import java.util.TreeMap;
+import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.LinkedList;
-import java.lang.reflect.InvocationTargetException;
-import junit.framework.TestCase;
+import java.util.TreeMap;
+
import junit.framework.Test;
+import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
@@ -170,12 +171,12 @@ public class LazyDynaBeanTestCase extend
bean.set(testProperty, testKey, testInteger1);
assertEquals("Check Mapped Property exists", HashMap.class,
bean.get(testProperty).getClass());
assertEquals("Check First Mapped Value is correct(a)", testInteger1,
bean.get(testProperty, testKey));
- assertEquals("Check First Mapped Value is correct(b)", testInteger1,
((HashMap)bean.get(testProperty)).get(testKey));
+ assertEquals("Check First Mapped Value is correct(b)", testInteger1,
((HashMap<?, ?>)bean.get(testProperty)).get(testKey));
// Set the property again - should set the new value
bean.set(testProperty, testKey, testInteger2);
assertEquals("Check Second Mapped Value is correct(a)", testInteger2,
bean.get(testProperty, testKey));
- assertEquals("Check Second Mapped Value is correct(b)", testInteger2,
((HashMap)bean.get(testProperty)).get(testKey));
+ assertEquals("Check Second Mapped Value is correct(b)", testInteger2,
((HashMap<?, ?>)bean.get(testProperty)).get(testKey));
}
/**
@@ -197,12 +198,12 @@ public class LazyDynaBeanTestCase extend
bean.set(testProperty, testKey, testInteger1);
assertEquals("Check Mapped Property exists", TreeMap.class,
bean.get(testProperty).getClass());
assertEquals("Check First Mapped Value is correct(a)", testInteger1,
bean.get(testProperty, testKey));
- assertEquals("Check First Mapped Value is correct(b)", testInteger1,
((TreeMap)bean.get(testProperty)).get(testKey));
+ assertEquals("Check First Mapped Value is correct(b)", testInteger1,
((TreeMap<?, ?>)bean.get(testProperty)).get(testKey));
// Set the property again - should set the new value
bean.set(testProperty, testKey, testInteger2);
assertEquals("Check Second Mapped Value is correct(a)", testInteger2,
bean.get(testProperty, testKey));
- assertEquals("Check Second Mapped Value is correct(b)", testInteger2,
((TreeMap)bean.get(testProperty)).get(testKey));
+ assertEquals("Check Second Mapped Value is correct(b)", testInteger2,
((TreeMap<?, ?>)bean.get(testProperty)).get(testKey));
}
/**
@@ -290,13 +291,13 @@ public class LazyDynaBeanTestCase extend
assertNotNull("Check Indexed Property is not null",
bean.get(testProperty));
assertEquals("Check Indexed Property is correct type",
ArrayList.class, bean.get(testProperty).getClass());
assertEquals("Check First Indexed Value is correct", testInteger1,
bean.get(testProperty, index));
- assertEquals("Check First Array length is correct", new
Integer(index+1), new Integer(((ArrayList)bean.get(testProperty)).size()));
+ assertEquals("Check First Array length is correct", new
Integer(index+1), new Integer(((ArrayList<?>)bean.get(testProperty)).size()));
// Set a second indexed value, should automatically grow the ArrayList
and set appropriate indexed value
index = index + 2;
bean.set(testProperty, index, testString1);
assertEquals("Check Second Indexed Value is correct", testString1,
bean.get(testProperty, index));
- assertEquals("Check Second Array length is correct", new
Integer(index+1), new Integer(((ArrayList)bean.get(testProperty)).size()));
+ assertEquals("Check Second Array length is correct", new
Integer(index+1), new Integer(((ArrayList<?>)bean.get(testProperty)).size()));
}
/**
@@ -320,13 +321,13 @@ public class LazyDynaBeanTestCase extend
bean.set(testProperty, index, testString1);
assertEquals("Check Property type is correct", LinkedList.class,
bean.get(testProperty).getClass());
assertEquals("Check First Indexed Value is correct", testString1,
bean.get(testProperty, index));
- assertEquals("Check First Array length is correct", new
Integer(index+1), new Integer(((LinkedList)bean.get(testProperty)).size()));
+ assertEquals("Check First Array length is correct", new
Integer(index+1), new Integer(((LinkedList<?>)bean.get(testProperty)).size()));
// Set a second indexed value, should automatically grow the
LinkedList and set appropriate indexed value
index = index + 2;
bean.set(testProperty, index, testInteger1);
assertEquals("Check Second Indexed Value is correct", testInteger1,
bean.get(testProperty, index));
- assertEquals("Check Second Array length is correct", new
Integer(index+1), new Integer(((LinkedList)bean.get(testProperty)).size()));
+ assertEquals("Check Second Array length is correct", new
Integer(index+1), new Integer(((LinkedList<?>)bean.get(testProperty)).size()));
}
/**