You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2013/11/08 22:08:33 UTC
svn commit: r1540186 [2/6] - in /commons/proper/beanutils/trunk: ./
src/changes/ src/main/java/org/apache/commons/beanutils/
src/main/java/org/apache/commons/beanutils/converters/
src/main/java/org/apache/commons/beanutils/locale/ src/test/java/org/apa...
Modified: commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/DynaBeanMapDecorator.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/DynaBeanMapDecorator.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/DynaBeanMapDecorator.java (original)
+++ commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/DynaBeanMapDecorator.java Fri Nov 8 21:08:30 2013
@@ -16,14 +16,6 @@
*/
package org.apache.commons.beanutils;
-import java.util.Map;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Collection;
-import java.util.Collections;
/**
* <p>Decorates a {@link DynaBean} to provide <code>Map</code> behaviour.</p>
@@ -66,331 +58,44 @@ import java.util.Collections;
* and <code>values()</code> methods create an <b><i>unmodifiable</i></b>
* <code>Set</code> and it does not support the Map's <code>clear()</code>
* and <code>remove()</code> operations.</p>
+ * <p>For reasons of backwards compatibility, the generic types of this
+ * {@code Map} implementation are {@code <Object, Object>}. However, the
+ * keys of the map are typically strings.</p>
*
* @since BeanUtils 1.8.0
* @version $Id$
+ * @deprecated Use {@link DynaBeanPropertyMapDecorator} instead. When adding
+ * generics it turned out that it was not possible to use the correct type
+ * parameters without breaking backwards compatibility. Therefore, class
+ * {@code DynaBeanPropertyMapDecorator} was introduced as a replacement.
*/
-public class DynaBeanMapDecorator implements Map {
-
- private final DynaBean dynaBean;
- private final boolean readOnly;
- private transient Set keySet;
-
- // ------------------- Constructors ----------------------------------
-
- /**
- * Constructs a read only Map for the specified
- * {@link DynaBean}.
- *
- * @param dynaBean The dyna bean being decorated
- * @throws IllegalArgumentException if the {@link DynaBean} is null.
- */
- public DynaBeanMapDecorator(DynaBean dynaBean) {
- this(dynaBean, true);
- }
-
+@Deprecated
+public class DynaBeanMapDecorator extends BaseDynaBeanMapDecorator<Object> {
/**
* Construct a Map for the specified {@link DynaBean}.
*
* @param dynaBean The dyna bean being decorated
- * @param readOnly <code>true</code> if the Mpa is read only
+ * @param readOnly <code>true</code> if the Map is read only
* otherwise <code>false</code>
* @throws IllegalArgumentException if the {@link DynaBean} is null.
*/
public DynaBeanMapDecorator(DynaBean dynaBean, boolean readOnly) {
- if (dynaBean == null) {
- throw new IllegalArgumentException("DynaBean is null");
- }
- this.dynaBean = dynaBean;
- this.readOnly = readOnly;
- }
-
-
- // ------------------- public Methods --------------------------------
-
-
- /**
- * Indicate whether the Map is read only.
- *
- * @return <code>true</code> if the Map is read only,
- * otherwise <code>false</code>.
- */
- public boolean isReadOnly() {
- return readOnly;
- }
-
- // ------------------- java.util.Map Methods -------------------------
-
- /**
- * clear() operation is not supported.
- *
- * @throws UnsupportedOperationException
- */
- public void clear() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Indicate whether the {@link DynaBean} contains a specified
- * value for one (or more) of its properties.
- *
- * @param key The {@link DynaBean}'s property name
- * @return <code>true</code> if one of the {@link DynaBean}'s
- * properties contains a specified value.
- */
- public boolean containsKey(Object key) {
- DynaClass dynaClass = getDynaBean().getDynaClass();
- DynaProperty dynaProperty = dynaClass.getDynaProperty(toString(key));
- return (dynaProperty == null ? false : true);
- }
-
- /**
- * Indicates whether the decorated {@link DynaBean} contains
- * a specified value.
- *
- * @param value The value to check for.
- * @return <code>true</code> if one of the the {@link DynaBean}'s
- * properties contains the specified value, otherwise
- * <code>false</code>.
- */
- public boolean containsValue(Object value) {
- DynaProperty[] properties = getDynaProperties();
- for (int i = 0; i < properties.length; i++) {
- String key = properties[i].getName();
- Object prop = getDynaBean().get(key);
- if (value == null) {
- if (prop == null) {
- return true;
- }
- } else {
- if (value.equals(prop)) {
- return true;
- }
- }
- }
- return false;
- }
-
- /**
- * <p>Returns the Set of the property/value mappings
- * in the decorated {@link DynaBean}.</p>
- *
- * <p>Each element in the Set is a <code>Map.Entry</code>
- * type.</p>
- *
- * @return An unmodifiable set of the DynaBean
- * property name/value pairs
- */
- public Set entrySet() {
- DynaProperty[] properties = getDynaProperties();
- Set set = new HashSet(properties.length);
- for (int i = 0; i < properties.length; i++) {
- String key = properties[i].getName();
- Object value = getDynaBean().get(key);
- set.add(new MapEntry(key, value));
- }
- return Collections.unmodifiableSet(set);
- }
-
- /**
- * Return the value for the specified key from
- * the decorated {@link DynaBean}.
- *
- * @param key The {@link DynaBean}'s property name
- * @return The value for the specified property.
- */
- public Object get(Object key) {
- return getDynaBean().get(toString(key));
- }
-
- /**
- * Indicate whether the decorated {@link DynaBean} has
- * any properties.
- *
- * @return <code>true</code> if the {@link DynaBean} has
- * no properties, otherwise <code>false</code>.
- */
- public boolean isEmpty() {
- return (getDynaProperties().length == 0);
+ super(dynaBean, readOnly);
}
/**
- * <p>Returns the Set of the property
- * names in the decorated {@link DynaBean}.</p>
- *
- * <p><b>N.B.</b>For {@link DynaBean}s whose associated {@link DynaClass}
- * is a {@link MutableDynaClass} a new Set is created every
- * time, otherwise the Set is created only once and cached.</p>
- *
- * @return An unmodifiable set of the {@link DynaBean}s
- * property names.
- */
- public Set keySet() {
- if (keySet != null) {
- return keySet;
- }
-
- // Create a Set of the keys
- DynaProperty[] properties = getDynaProperties();
- Set set = new HashSet(properties.length);
- for (int i = 0; i < properties.length; i++) {
- set.add(properties[i].getName());
- }
- set = Collections.unmodifiableSet(set);
-
- // Cache the keySet if Not a MutableDynaClass
- DynaClass dynaClass = getDynaBean().getDynaClass();
- if (!(dynaClass instanceof MutableDynaClass)) {
- keySet = set;
- }
-
- return set;
-
- }
-
- /**
- * Set the value for the specified property in
- * the decorated {@link DynaBean}.
- *
- * @param key The {@link DynaBean}'s property name
- * @param value The value for the specified property.
- * @return The previous property's value.
- * @throws UnsupportedOperationException if
- * <code>isReadOnly()</code> is true.
- */
- public Object put(Object key, Object value) {
- if (isReadOnly()) {
- throw new UnsupportedOperationException("Map is read only");
- }
- String property = toString(key);
- Object previous = getDynaBean().get(property);
- getDynaBean().set(property, value);
- return previous;
- }
-
- /**
- * Copy the contents of a Map to the decorated {@link DynaBean}.
- *
- * @param map The Map of values to copy.
- * @throws UnsupportedOperationException if
- * <code>isReadOnly()</code> is true.
- */
- public void putAll(Map map) {
- if (isReadOnly()) {
- throw new UnsupportedOperationException("Map is read only");
- }
- Iterator keys = map.keySet().iterator();
- while (keys.hasNext()) {
- Object key = keys.next();
- put(key, map.get(key));
- }
- }
-
- /**
- * remove() operation is not supported.
- *
- * @param key The {@link DynaBean}'s property name
- * @return the value removed
- * @throws UnsupportedOperationException
- */
- public Object remove(Object key) {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Returns the number properties in the decorated
+ * Constructs a read only Map for the specified
* {@link DynaBean}.
- * @return The number of properties.
- */
- public int size() {
- return getDynaProperties().length;
- }
-
- /**
- * Returns the set of property values in the
- * decorated {@link DynaBean}.
- *
- * @return Unmodifiable collection of values.
- */
- public Collection values() {
- DynaProperty[] properties = getDynaProperties();
- List values = new ArrayList(properties.length);
- for (int i = 0; i < properties.length; i++) {
- String key = properties[i].getName();
- Object value = getDynaBean().get(key);
- values.add(value);
- }
- return Collections.unmodifiableList(values);
- }
-
- // ------------------- protected Methods -----------------------------
-
- /**
- * Provide access to the underlying {@link DynaBean}
- * this Map decorates.
- *
- * @return the decorated {@link DynaBean}.
- */
- public DynaBean getDynaBean() {
- return dynaBean;
- }
-
- // ------------------- private Methods -------------------------------
-
- /**
- * Convenience method to retrieve the {@link DynaProperty}s
- * for this {@link DynaClass}.
- *
- * @return The an array of the {@link DynaProperty}s.
- */
- private DynaProperty[] getDynaProperties() {
- return getDynaBean().getDynaClass().getDynaProperties();
- }
-
- /**
- * Convenience method to convert an Object
- * to a String.
*
- * @param obj The Object to convert
- * @return String representation of the object
+ * @param dynaBean The dyna bean being decorated
+ * @throws IllegalArgumentException if the {@link DynaBean} is null.
*/
- private String toString(Object obj) {
- return (obj == null ? null : obj.toString());
+ public DynaBeanMapDecorator(DynaBean dynaBean) {
+ super(dynaBean);
}
- /**
- * Map.Entry implementation.
- */
- private static class MapEntry implements Map.Entry {
- private final Object key;
- private final Object value;
- MapEntry(Object key, Object value) {
- this.key = key;
- this.value = value;
- }
- @Override
- public boolean equals(Object o) {
- if (!(o instanceof Map.Entry)) {
- return false;
- }
- Map.Entry e = (Map.Entry)o;
- return ((key.equals(e.getKey())) &&
- (value == null ? e.getValue() == null
- : value.equals(e.getValue())));
- }
- @Override
- public int hashCode() {
- return key.hashCode() + (value == null ? 0 : value.hashCode());
- }
- public Object getKey() {
- return key;
- }
- public Object getValue() {
- return value;
- }
- public Object setValue(Object value) {
- throw new UnsupportedOperationException();
- }
+ @Override
+ protected Object convertKey(String propertyName) {
+ return propertyName;
}
-
}
Modified: commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/DynaProperty.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/DynaProperty.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/DynaProperty.java (original)
+++ commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/DynaProperty.java Fri Nov 8 21:08:30 2013
@@ -20,9 +20,9 @@ package org.apache.commons.beanutils;
import java.io.IOException;
-import java.io.Serializable;
-import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
import java.io.StreamCorruptedException;
import java.util.List;
import java.util.Map;
@@ -84,7 +84,7 @@ public class DynaProperty implements Ser
* @param name Name of the property being described
* @param type Java class representing the property data type
*/
- public DynaProperty(String name, Class type) {
+ public DynaProperty(String name, Class<?> type) {
super();
this.name = name;
@@ -103,7 +103,7 @@ public class DynaProperty implements Ser
* @param type Java class representing the property data type
* @param contentType Class that all indexed or mapped elements are instances of
*/
- public DynaProperty(String name, Class type, Class contentType) {
+ public DynaProperty(String name, Class<?> type, Class<?> contentType) {
super();
this.name = name;
@@ -125,7 +125,7 @@ public class DynaProperty implements Ser
}
/** Property type */
- protected transient Class type = null;
+ protected transient Class<?> type = null;
/**
* <p>Gets the Java class representing the data type of the underlying property
* values.</p>
@@ -138,13 +138,13 @@ public class DynaProperty implements Ser
*
* @return the property type
*/
- public Class getType() {
+ public Class<?> getType() {
return (this.type);
}
/** The <em>(optional)</em> type of content elements for indexed <code>DynaProperty</code> */
- protected transient Class contentType;
+ protected transient Class<?> contentType;
/**
* Gets the <em>(optional)</em> type of the indexed content for <code>DynaProperty</code>'s
* that support this feature.
@@ -156,7 +156,7 @@ public class DynaProperty implements Ser
* @return the Class for the content type if this is an indexed <code>DynaProperty</code>
* and this feature is supported. Otherwise null.
*/
- public Class getContentType() {
+ public Class<?> getContentType() {
return contentType;
}
@@ -285,7 +285,7 @@ public class DynaProperty implements Ser
/**
* Write a class using safe encoding to workaround java 1.3 serialization bug.
*/
- private void writeAnyClass(Class clazz, ObjectOutputStream out) throws IOException {
+ private void writeAnyClass(Class<?> clazz, ObjectOutputStream out) throws IOException {
// safely write out any class
int primitiveType = 0;
if (Boolean.TYPE.equals(clazz)) {
@@ -341,7 +341,7 @@ public class DynaProperty implements Ser
/**
* Reads a class using safe encoding to workaround java 1.3 serialization bug.
*/
- private Class readAnyClass(ObjectInputStream in) throws IOException, ClassNotFoundException {
+ private Class<?> readAnyClass(ObjectInputStream in) throws IOException, ClassNotFoundException {
// read back type class safely
if (in.readBoolean()) {
// it's a type constant
@@ -365,7 +365,7 @@ public class DynaProperty implements Ser
} else {
// it's another class
- return ((Class) in.readObject());
+ return ((Class<?>) in.readObject());
}
}
}
\ No newline at end of file
Modified: commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/JDBCDynaClass.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/JDBCDynaClass.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/JDBCDynaClass.java (original)
+++ commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/JDBCDynaClass.java Fri Nov 8 21:08:30 2013
@@ -61,13 +61,13 @@ abstract class JDBCDynaClass implements
* instances will be the same instances as those in the
* <code>properties</code> list.</p>
*/
- protected Map propertiesMap = new HashMap();
+ protected Map<String, DynaProperty> propertiesMap = new HashMap<String, DynaProperty>();
/**
* Cross Reference for column name --> dyna property name
* (needed when lowerCase option is true)
*/
- private Map columnNameXref;
+ private Map<String, String> columnNameXref;
// ------------------------------------------------------ DynaClass Methods
@@ -97,7 +97,7 @@ abstract class JDBCDynaClass implements
if (name == null) {
throw new IllegalArgumentException("No property name specified");
}
- return ((DynaProperty) propertiesMap.get(name));
+ return (propertiesMap.get(name));
}
@@ -150,7 +150,7 @@ abstract class JDBCDynaClass implements
* @exception SQLException if an exception was thrown trying to load
* the specified class
*/
- protected Class loadClass(String className) throws SQLException {
+ protected Class<?> loadClass(String className) throws SQLException {
try {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
@@ -190,7 +190,7 @@ abstract class JDBCDynaClass implements
String name = lowerCase ? columnName.toLowerCase() : columnName;
if (!name.equals(columnName)) {
if (columnNameXref == null) {
- columnNameXref = new HashMap();
+ columnNameXref = new HashMap<String, String>();
}
columnNameXref.put(name, columnName);
}
@@ -214,7 +214,7 @@ abstract class JDBCDynaClass implements
// Default to Object type if no class name could be retrieved
// from the metadata
- Class clazz = Object.class;
+ Class<?> clazz = Object.class;
if (className != null) {
clazz = loadClass(className);
}
@@ -236,7 +236,7 @@ abstract class JDBCDynaClass implements
protected void introspect(ResultSet resultSet) throws SQLException {
// Accumulate an ordered list of DynaProperties
- ArrayList list = new ArrayList();
+ ArrayList<DynaProperty> list = new ArrayList<DynaProperty>();
ResultSetMetaData metadata = resultSet.getMetaData();
int n = metadata.getColumnCount();
for (int i = 1; i <= n; i++) { // JDBC is one-relative!
@@ -248,7 +248,7 @@ abstract class JDBCDynaClass implements
// Convert this list into the internal data structures we need
properties =
- (DynaProperty[]) list.toArray(new DynaProperty[list.size()]);
+ list.toArray(new DynaProperty[list.size()]);
for (int i = 0; i < properties.length; i++) {
propertiesMap.put(properties[i].getName(), properties[i]);
}
@@ -270,7 +270,7 @@ abstract class JDBCDynaClass implements
throw new IllegalArgumentException("Invalid name '" + name + "'");
}
String columnName = getColumnName(name);
- Class type = property.getType();
+ Class<?> type = property.getType();
// java.sql.Date
if (type.equals(Date.class)) {
@@ -299,7 +299,7 @@ abstract class JDBCDynaClass implements
*/
protected String getColumnName(String name) {
if (columnNameXref != null && columnNameXref.containsKey(name)) {
- return (String)columnNameXref.get(name);
+ return columnNameXref.get(name);
} else {
return name;
}
Modified: commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/LazyDynaBean.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/LazyDynaBean.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/LazyDynaBean.java (original)
+++ commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/LazyDynaBean.java Fri Nov 8 21:08:30 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<String, Object> mapDecorator;
/**
* The <code>MutableDynaClass</code> "base class" that this DynaBean
@@ -202,10 +203,10 @@ public class LazyDynaBean implements Dyn
*
* @return a Map representation of this DynaBean
*/
- public Map getMap() {
+ public Map<String, Object> getMap() {
// cache the Map
if (mapDecorator == null) {
- mapDecorator = new DynaBeanMapDecorator(this);
+ mapDecorator = new DynaBeanPropertyMapDecorator(this);
}
return mapDecorator;
}
@@ -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/trunk/src/main/java/org/apache/commons/beanutils/LazyDynaClass.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/LazyDynaClass.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/LazyDynaClass.java (original)
+++ commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/LazyDynaClass.java Fri Nov 8 21:08:30 2013
@@ -79,7 +79,7 @@ public class LazyDynaClass extends Basic
* @param name Name of this DynaBean class
* @param dynaBeanClass The implementation class for new instances
*/
- public LazyDynaClass(String name, Class dynaBeanClass) {
+ public LazyDynaClass(String name, Class<?> dynaBeanClass) {
this(name, dynaBeanClass, null);
}
@@ -97,10 +97,10 @@ public class LazyDynaClass extends Basic
* Construct a new LazyDynaClass with the specified name, DynaBean class and properties.
*
* @param name Name of this DynaBean class
- * @param dynaBeanClass The implementation class for new intances
+ * @param dynaBeanClass The implementation class for new instances
* @param properties Property descriptors for the supported properties
*/
- public LazyDynaClass(String name, Class dynaBeanClass, DynaProperty properties[]) {
+ public LazyDynaClass(String name, Class<?> dynaBeanClass, DynaProperty properties[]) {
super(name, dynaBeanClass, properties);
}
@@ -177,7 +177,7 @@ public class LazyDynaClass extends Basic
* @exception IllegalStateException if this DynaClass is currently
* restricted, so no new properties can be added
*/
- public void add(String name, Class type) {
+ public void add(String name, Class<?> type) {
if (type == null) {
add(name);
} else {
@@ -206,7 +206,7 @@ public class LazyDynaClass extends Basic
*
* @exception UnsupportedOperationException anytime this method is called
*/
- public void add(String name, Class type, boolean readable, boolean writeable) {
+ public void add(String name, Class<?> type, boolean readable, boolean writeable) {
throw new java.lang.UnsupportedOperationException("readable/writable properties not supported");
}
@@ -320,7 +320,7 @@ public class LazyDynaClass extends Basic
throw new IllegalArgumentException("Property name is missing.");
}
- DynaProperty dynaProperty = (DynaProperty)propertiesMap.get(name);
+ DynaProperty dynaProperty = propertiesMap.get(name);
// If it doesn't exist and returnNull is false
// create a new DynaProperty
Modified: commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/LazyDynaList.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/LazyDynaList.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/LazyDynaList.java (original)
+++ commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/LazyDynaList.java Fri Nov 8 21:08:30 2013
@@ -16,11 +16,10 @@
*/
package org.apache.commons.beanutils;
+import java.lang.reflect.Array;
import java.util.ArrayList;
-import java.util.Map;
import java.util.Collection;
-import java.util.Iterator;
-import java.lang.reflect.Array;
+import java.util.Map;
/**
* <h2><i>Lazy</i> DynaBean List.</h2>
@@ -159,7 +158,7 @@ import java.lang.reflect.Array;
* @version $Id$
* @since 1.8.0
*/
-public class LazyDynaList extends ArrayList {
+public class LazyDynaList extends ArrayList<Object> {
/**
* The DynaClass of the List's elements.
@@ -179,12 +178,12 @@ public class LazyDynaList extends ArrayL
/**
* The type of the List's elements.
*/
- private Class elementType;
+ private Class<?> elementType;
/**
* The DynaBean type of the List's elements.
*/
- private Class elementDynaBeanType;
+ private Class<?> elementDynaBeanType;
// ------------------- Constructors ------------------------------
@@ -224,7 +223,7 @@ public class LazyDynaList extends ArrayL
*
* @param elementType The Type of the List's elements.
*/
- public LazyDynaList(Class elementType) {
+ public LazyDynaList(Class<?> elementType) {
super();
setElementType(elementType);
}
@@ -233,9 +232,9 @@ public class LazyDynaList extends ArrayL
* Construct a LazyDynaList populated with the
* elements of a Collection.
*
- * @param collection The Collection to poulate the List from.
+ * @param collection The Collection to populate the List from.
*/
- public LazyDynaList(Collection collection) {
+ public LazyDynaList(Collection<?> collection) {
super(collection.size());
addAll(collection);
}
@@ -244,7 +243,7 @@ public class LazyDynaList extends ArrayL
* Construct a LazyDynaList populated with the
* elements of an Array.
*
- * @param array The Array to poulate the List from.
+ * @param array The Array to populate the List from.
*/
public LazyDynaList(Object[] array) {
super(array.length);
@@ -299,7 +298,7 @@ public class LazyDynaList extends ArrayL
* @return true if elements were added.
*/
@Override
- public boolean addAll(Collection collection) {
+ public boolean addAll(Collection<?> collection) {
if (collection == null || collection.size() == 0) {
return false;
@@ -307,9 +306,8 @@ public class LazyDynaList extends ArrayL
ensureCapacity(size() + collection.size());
- Iterator iterator = collection.iterator();
- while (iterator.hasNext()) {
- add(iterator.next());
+ for (Object e : collection) {
+ add(e);
}
return true;
@@ -329,7 +327,7 @@ public class LazyDynaList extends ArrayL
* @return true if elements were added.
*/
@Override
- public boolean addAll(int index, Collection collection) {
+ public boolean addAll(int index, Collection<?> collection) {
if (collection == null || collection.size() == 0) {
return false;
@@ -337,7 +335,7 @@ public class LazyDynaList extends ArrayL
ensureCapacity((index > size() ? index : size()) + collection.size());
- // Call "tranform" with first element, before
+ // Call "transform" with first element, before
// List is "grown" to ensure the correct DynaClass
// is set.
if (size() == 0) {
@@ -346,9 +344,9 @@ public class LazyDynaList extends ArrayL
growList(index);
- Iterator iterator = collection.iterator();
- while (iterator.hasNext()) {
- add(index++, iterator.next());
+ int currentIndex = index;
+ for (Object e : collection) {
+ add(currentIndex++, e);
}
return true;
@@ -435,36 +433,40 @@ public class LazyDynaList extends ArrayL
/**
* <p>Converts the List to an Array of the specified type.</p>
*
+ * @param <T> The type of the array elements
* @param model The model for the type of array to return
* @return An Array of the elements in this List.
*/
@Override
- public Object[] toArray(Object[] model) {
-
- // Allocate the Array
- Class arrayType = model.getClass().getComponentType();
- Object[] array = (Object[])Array.newInstance(arrayType, size());
+ public <T> T[] toArray(T[] model) {
- if (size() == 0 && elementType == null) {
- return new LazyDynaBean[0];
+ Class<?> arrayType = model.getClass().getComponentType();
+ if ((DynaBean.class.isAssignableFrom(arrayType))
+ || (size() == 0 && elementType == null)) {
+ return super.toArray(model);
}
- if ((DynaBean.class.isAssignableFrom(arrayType))) {
- for (int i = 0; i < size(); i++) {
- array[i] = get(i);
+ if ((arrayType.isAssignableFrom(elementType))) {
+ T[] array;
+ if (model.length >= size()) {
+ array = model;
+ } else {
+ @SuppressWarnings("unchecked")
+ // This is safe because we know the element type
+ T[] tempArray = (T[]) Array.newInstance(arrayType, size());
+ array = tempArray;
}
- return array;
- }
- if ((arrayType.isAssignableFrom(elementType))) {
for (int i = 0; i < size(); i++) {
+ Object elem;
if (Map.class.isAssignableFrom(elementType)) {
- array[i] = ((LazyDynaMap)get(i)).getMap();
+ elem = ((LazyDynaMap) get(i)).getMap();
} else if (DynaBean.class.isAssignableFrom(elementType)) {
- array[i] = get(i);
+ elem = get(i);
} else {
- array[i] = ((WrapDynaBean)get(i)).getInstance();
+ elem = ((WrapDynaBean) get(i)).getInstance();
}
+ Array.set(array, i, elem);
}
return array;
}
@@ -504,7 +506,7 @@ public class LazyDynaList extends ArrayL
* @exception IllegalArgumentException if the List already
* contains elements or the DynaClass is null.
*/
- public void setElementType(Class elementType) {
+ public void setElementType(Class<?> elementType) {
if (elementType == null) {
throw new IllegalArgumentException("Element Type is missing");
@@ -529,7 +531,7 @@ public class LazyDynaList extends ArrayL
// Create a DynaBean
DynaBean dynaBean = null;
if (Map.class.isAssignableFrom(elementType)) {
- dynaBean = new LazyDynaMap((Map)object);
+ dynaBean = createDynaBeanForMapProperty(object);
this.elementDynaClass = dynaBean.getDynaClass();
} else if (DynaBean.class.isAssignableFrom(elementType)) {
dynaBean = (DynaBean)object;
@@ -623,14 +625,14 @@ public class LazyDynaList extends ArrayL
* <li>DynaBeans are unchanged.</li>
* </li>
*
- * @param element The element to transformt.
+ * @param element The element to transformed.
* @param The DynaBean to store in the List.
*/
private DynaBean transform(Object element) {
DynaBean dynaBean = null;
- Class newDynaBeanType = null;
- Class newElementType = null;
+ Class<?> newDynaBeanType = null;
+ Class<?> newElementType = null;
// Create a new element
if (element == null) {
@@ -661,7 +663,7 @@ public class LazyDynaList extends ArrayL
// Transform Object to a DynaBean
newElementType = element.getClass();
if (Map.class.isAssignableFrom(element.getClass())) {
- dynaBean = new LazyDynaMap((Map)element);
+ dynaBean = createDynaBeanForMapProperty(element);
} else if (DynaBean.class.isAssignableFrom(element.getClass())) {
dynaBean = (DynaBean)element;
} else {
@@ -692,6 +694,19 @@ public class LazyDynaList extends ArrayL
}
/**
+ * Creates a new {@code LazyDynaMap} object for the given property value.
+ *
+ * @param value the property value
+ * @return the newly created {@code LazyDynaMap}
+ */
+ private LazyDynaMap createDynaBeanForMapProperty(Object value) {
+ @SuppressWarnings("unchecked")
+ // map properties are always stored as Map<String, Object>
+ Map<String, Object> valueMap = (Map<String, Object>) value;
+ return new LazyDynaMap(valueMap);
+ }
+
+ /**
* Return the DynaClass.
*/
private DynaClass getDynaClass() {
Modified: commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/LazyDynaMap.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/LazyDynaMap.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/LazyDynaMap.java (original)
+++ commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/LazyDynaMap.java Fri Nov 8 21:08:30 2013
@@ -17,7 +17,6 @@
package org.apache.commons.beanutils;
import java.util.Map;
-import java.util.Iterator;
/**
* <p>Provides a <i>light weight</i> <code>DynaBean</code> facade to a <code>Map</code>
@@ -74,7 +73,7 @@ public class LazyDynaMap extends LazyDyn
* Default Constructor.
*/
public LazyDynaMap() {
- this(null, (Map)null);
+ this(null, (Map<String, Object>)null);
}
/**
@@ -83,7 +82,7 @@ public class LazyDynaMap extends LazyDyn
* @param name Name of this DynaBean class
*/
public LazyDynaMap(String name) {
- this(name, (Map)null);
+ this(name, (Map<String, Object>)null);
}
/**
@@ -91,7 +90,7 @@ public class LazyDynaMap extends LazyDyn
*
* @param values The Map backing this <code>LazyDynaMap</code>
*/
- public LazyDynaMap(Map values) {
+ public LazyDynaMap(Map<String, Object> values) {
this(null, values);
}
@@ -101,7 +100,7 @@ public class LazyDynaMap extends LazyDyn
* @param name Name of this DynaBean class
* @param values The Map backing this <code>LazyDynaMap</code>
*/
- public LazyDynaMap(String name, Map values) {
+ public LazyDynaMap(String name, Map<String, Object> values) {
this.name = name == null ? "LazyDynaMap" : name;
this.values = values == null ? newMap() : values;
this.dynaClass = this;
@@ -123,7 +122,7 @@ public class LazyDynaMap extends LazyDyn
* @param properties Property descriptors for the supported properties
*/
public LazyDynaMap(String name, DynaProperty[] properties) {
- this(name, (Map)null);
+ this(name, (Map<String, Object>)null);
if (properties != null) {
for (int i = 0; i < properties.length; i++) {
add(properties[i]);
@@ -147,7 +146,7 @@ public class LazyDynaMap extends LazyDyn
*
* @param values The new Map of values
*/
- public void setMap(Map values) {
+ public void setMap(Map<String, Object> values) {
this.values = values;
}
@@ -157,7 +156,7 @@ public class LazyDynaMap extends LazyDyn
* @since 1.8.0
*/
@Override
- public Map getMap() {
+ public Map<String, Object> getMap() {
return values;
}
@@ -252,12 +251,11 @@ public class LazyDynaMap extends LazyDyn
int i = 0;
DynaProperty[] properties = new DynaProperty[values.size()];
- Iterator iterator = values.keySet().iterator();
-
- while (iterator.hasNext()) {
- String name = (String)iterator.next();
+ for (Map.Entry<String, Object> e : values.entrySet()) {
+ String name = e.getKey();
Object value = values.get(name);
- properties[i++] = new DynaProperty(name, value == null ? null : value.getClass());
+ properties[i++] = new DynaProperty(name, value == null ? null
+ : value.getClass());
}
return properties;
@@ -272,9 +270,12 @@ public class LazyDynaMap extends LazyDyn
public DynaBean newInstance() {
// Create a new instance of the Map
- Map newMap = null;
+ Map<String, Object> newMap = null;
try {
- newMap = getMap().getClass().newInstance();
+ @SuppressWarnings("unchecked")
+ // The new map is used as properties map
+ Map<String, Object> temp = getMap().getClass().newInstance();
+ newMap = temp;
} catch(Exception ex) {
newMap = newMap();
}
@@ -340,7 +341,7 @@ public class LazyDynaMap extends LazyDyn
* @exception IllegalStateException if this DynaClass is currently
* restricted, so no new properties can be added
*/
- public void add(String name, Class type) {
+ public void add(String name, Class<?> type) {
if (name == null) {
throw new IllegalArgumentException("Property name is missing.");
@@ -380,7 +381,7 @@ public class LazyDynaMap extends LazyDyn
*
* @exception UnsupportedOperationException anytime this method is called
*/
- public void add(String name, Class type, boolean readable, boolean writeable) {
+ public void add(String name, Class<?> type, boolean readable, boolean writeable) {
throw new java.lang.UnsupportedOperationException("readable/writable properties not supported");
}
Modified: commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/MappedPropertyDescriptor.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/MappedPropertyDescriptor.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/MappedPropertyDescriptor.java (original)
+++ commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/MappedPropertyDescriptor.java Fri Nov 8 21:08:30 2013
@@ -50,7 +50,7 @@ public class MappedPropertyDescriptor ex
/**
* The underlying data type of the property we are describing.
*/
- private Reference mappedPropertyTypeRef;
+ private Reference<Class<?>> mappedPropertyTypeRef;
/**
* The reader method for this property (if any).
@@ -65,7 +65,7 @@ public class MappedPropertyDescriptor ex
/**
* The parameter types array for the reader method signature.
*/
- private static final Class[] STRING_CLASS_PARAMETER = new Class[]{String.class};
+ private static final Class<?>[] STRING_CLASS_PARAMETER = new Class[]{String.class};
// ----------------------------------------------------------- Constructors
@@ -85,7 +85,7 @@ public class MappedPropertyDescriptor ex
* @exception IntrospectionException if an exception occurs during
* introspection.
*/
- public MappedPropertyDescriptor(String propertyName, Class beanClass)
+ public MappedPropertyDescriptor(String propertyName, Class<?> beanClass)
throws IntrospectionException {
super(propertyName, null, null);
@@ -109,7 +109,7 @@ public class MappedPropertyDescriptor ex
mappedReadMethod = getMethod(beanClass, "is" + base,
STRING_CLASS_PARAMETER);
}
- Class[] params = { String.class, mappedReadMethod.getReturnType() };
+ Class<?>[] params = { String.class, mappedReadMethod.getReturnType() };
mappedWriteMethod = getMethod(beanClass, "set" + base, params);
} catch (IntrospectionException e) {
/* Swallow IntrospectionException
@@ -151,7 +151,7 @@ public class MappedPropertyDescriptor ex
* @exception IntrospectionException if an exception occurs during
* introspection.
*/
- public MappedPropertyDescriptor(String propertyName, Class beanClass,
+ public MappedPropertyDescriptor(String propertyName, Class<?> beanClass,
String mappedGetterName, String mappedSetterName)
throws IntrospectionException {
@@ -170,7 +170,7 @@ public class MappedPropertyDescriptor ex
getMethod(beanClass, mappedGetterName, STRING_CLASS_PARAMETER);
if (mappedReadMethod != null) {
- Class[] params = { String.class, mappedReadMethod.getReturnType() };
+ Class<?>[] params = { String.class, mappedReadMethod.getReturnType() };
mappedWriteMethod =
getMethod(beanClass, mappedSetterName, params);
} else {
@@ -226,8 +226,8 @@ public class MappedPropertyDescriptor ex
* <p>
* This is the type that will be returned by the mappedReadMethod.
*/
- public Class getMappedPropertyType() {
- return (Class)mappedPropertyTypeRef.get();
+ public Class<?> getMappedPropertyType() {
+ return mappedPropertyTypeRef.get();
}
/**
@@ -286,7 +286,7 @@ public class MappedPropertyDescriptor ex
try {
Method mappedReadMethod = getMappedReadMethod();
Method mappedWriteMethod = getMappedWriteMethod();
- Class mappedPropertyType = null;
+ Class<?> mappedPropertyType = null;
if (mappedReadMethod != null) {
if (mappedReadMethod.getParameterTypes().length != 1) {
throw new IntrospectionException
@@ -301,7 +301,7 @@ public class MappedPropertyDescriptor ex
}
if (mappedWriteMethod != null) {
- Class[] params = mappedWriteMethod.getParameterTypes();
+ Class<?>[] params = mappedWriteMethod.getParameterTypes();
if (params.length != 2) {
throw new IntrospectionException
("bad mapped write method arg count");
@@ -313,7 +313,7 @@ public class MappedPropertyDescriptor ex
}
mappedPropertyType = params[1];
}
- mappedPropertyTypeRef = new SoftReference(mappedPropertyType);
+ mappedPropertyTypeRef = new SoftReference<Class<?>>(mappedPropertyType);
} catch (IntrospectionException ex) {
throw ex;
}
@@ -338,11 +338,11 @@ public class MappedPropertyDescriptor ex
/**
* Find a method on a class with a specified number of parameters.
*/
- private static Method internalGetMethod(Class initial, String methodName,
+ private static Method internalGetMethod(Class<?> initial, String methodName,
int parameterCount) {
// For overridden methods we need to find the most derived version.
// So we start with the given class and walk up the superclass chain.
- for (Class clazz = initial; clazz != null; clazz = clazz.getSuperclass()) {
+ for (Class<?> clazz = initial; clazz != null; clazz = clazz.getSuperclass()) {
Method[] methods = clazz.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
@@ -365,7 +365,7 @@ public class MappedPropertyDescriptor ex
// Now check any inherited interfaces. This is necessary both when
// the argument class is itself an interface, and when the argument
// class is an abstract class.
- Class[] interfaces = initial.getInterfaces();
+ Class<?>[] interfaces = initial.getInterfaces();
for (int i = 0; i < interfaces.length; i++) {
Method method = internalGetMethod(interfaces[i], methodName, parameterCount);
if (method != null) {
@@ -379,7 +379,7 @@ public class MappedPropertyDescriptor ex
/**
* Find a method on a class with a specified number of parameters.
*/
- private static Method getMethod(Class clazz, String methodName, int parameterCount)
+ private static Method getMethod(Class<?> clazz, String methodName, int parameterCount)
throws IntrospectionException {
if (methodName == null) {
return null;
@@ -398,7 +398,7 @@ public class MappedPropertyDescriptor ex
/**
* Find a method on a class with a specified parameter list.
*/
- private static Method getMethod(Class clazz, String methodName, Class[] parameterTypes)
+ private static Method getMethod(Class<?> clazz, String methodName, Class<?>[] parameterTypes)
throws IntrospectionException {
if (methodName == null) {
return null;
@@ -427,21 +427,21 @@ public class MappedPropertyDescriptor ex
private static class MappedMethodReference {
private String className;
private String methodName;
- private Reference methodRef;
- private Reference classRef;
- private Reference writeParamTypeRef0;
- private Reference writeParamTypeRef1;
+ private Reference<Method> methodRef;
+ private Reference<Class<?>> classRef;
+ private Reference<Class<?>> writeParamTypeRef0;
+ private Reference<Class<?>> writeParamTypeRef1;
private String[] writeParamClassNames;
MappedMethodReference(Method m) {
if (m != null) {
className = m.getDeclaringClass().getName();
methodName = m.getName();
- methodRef = new SoftReference(m);
- classRef = new WeakReference(m.getDeclaringClass());
- Class[] types = m.getParameterTypes();
+ methodRef = new SoftReference<Method>(m);
+ classRef = new WeakReference<Class<?>>(m.getDeclaringClass());
+ Class<?>[] types = m.getParameterTypes();
if (types.length == 2) {
- writeParamTypeRef0 = new WeakReference(types[0]);
- writeParamTypeRef1 = new WeakReference(types[1]);
+ writeParamTypeRef0 = new WeakReference<Class<?>>(types[0]);
+ writeParamTypeRef1 = new WeakReference<Class<?>>(types[1]);
writeParamClassNames = new String[2];
writeParamClassNames[0] = types[0].getName();
writeParamClassNames[1] = types[1].getName();
@@ -452,34 +452,34 @@ public class MappedPropertyDescriptor ex
if (methodRef == null) {
return null;
}
- Method m = (Method)methodRef.get();
+ Method m = methodRef.get();
if (m == null) {
- Class clazz = (Class)classRef.get();
+ Class<?> clazz = classRef.get();
if (clazz == null) {
clazz = reLoadClass();
if (clazz != null) {
- classRef = new WeakReference(clazz);
+ classRef = new WeakReference<Class<?>>(clazz);
}
}
if (clazz == null) {
throw new RuntimeException("Method " + methodName + " for " +
className + " could not be reconstructed - class reference has gone");
}
- Class[] paramTypes = null;
+ Class<?>[] paramTypes = null;
if (writeParamClassNames != null) {
paramTypes = new Class[2];
- paramTypes[0] = (Class)writeParamTypeRef0.get();
+ paramTypes[0] = writeParamTypeRef0.get();
if (paramTypes[0] == null) {
paramTypes[0] = reLoadClass(writeParamClassNames[0]);
if (paramTypes[0] != null) {
- writeParamTypeRef0 = new WeakReference(paramTypes[0]);
+ writeParamTypeRef0 = new WeakReference<Class<?>>(paramTypes[0]);
}
}
- paramTypes[1] = (Class)writeParamTypeRef1.get();
+ paramTypes[1] = writeParamTypeRef1.get();
if (paramTypes[1] == null) {
paramTypes[1] = reLoadClass(writeParamClassNames[1]);
if (paramTypes[1] != null) {
- writeParamTypeRef1 = new WeakReference(paramTypes[1]);
+ writeParamTypeRef1 = new WeakReference<Class<?>>(paramTypes[1]);
}
}
} else {
@@ -493,7 +493,7 @@ public class MappedPropertyDescriptor ex
throw new RuntimeException("Method " + methodName + " for " +
className + " could not be reconstructed - method not found");
}
- methodRef = new SoftReference(m);
+ methodRef = new SoftReference<Method>(m);
}
return m;
}
@@ -501,14 +501,14 @@ public class MappedPropertyDescriptor ex
/**
* Try to re-load the class
*/
- private Class reLoadClass() {
+ private Class<?> reLoadClass() {
return reLoadClass(className);
}
/**
* Try to re-load the class
*/
- private Class reLoadClass(String name) {
+ private Class<?> reLoadClass(String name) {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Modified: commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/MethodUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/MethodUtils.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/MethodUtils.java (original)
+++ commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/MethodUtils.java Fri Nov 8 21:08:30 2013
@@ -32,7 +32,7 @@ import org.apache.commons.logging.LogFac
/**
- * <p> Utility reflection methods focussed on methods in general rather than properties in particular. </p>
+ * <p> Utility reflection methods focused on methods in general rather than properties in particular. </p>
*
* <h3>Known Limitations</h3>
* <h4>Accessing Public Methods In A Default Access Superclass</h4>
@@ -77,7 +77,7 @@ public class MethodUtils {
private static boolean CACHE_METHODS = true;
/** An empty class array */
- private static final Class[] EMPTY_CLASS_PARAMETERS = new Class[0];
+ private static final Class<?>[] EMPTY_CLASS_PARAMETERS = new Class[0];
/** An empty object array */
private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
@@ -101,7 +101,8 @@ public class MethodUtils {
* class via different classloaders will generate non-equal MethodDescriptor
* objects and hence end up with different entries in the map.
*/
- private static final Map cache = Collections.synchronizedMap(new WeakHashMap());
+ private static final Map<MethodDescriptor, Reference<Method>> cache = Collections
+ .synchronizedMap(new WeakHashMap<MethodDescriptor, Reference<Method>>());
// --------------------------------------------------------- Public Methods
@@ -214,7 +215,7 @@ public class MethodUtils {
args = EMPTY_OBJECT_ARRAY;
}
int arguments = args.length;
- Class[] parameterTypes = new Class[arguments];
+ Class<?>[] parameterTypes = new Class[arguments];
for (int i = 0; i < arguments; i++) {
parameterTypes[i] = args[i].getClass();
}
@@ -253,7 +254,7 @@ public class MethodUtils {
Object object,
String methodName,
Object[] args,
- Class[] parameterTypes)
+ Class<?>[] parameterTypes)
throws
NoSuchMethodException,
IllegalAccessException,
@@ -344,7 +345,7 @@ public class MethodUtils {
args = EMPTY_OBJECT_ARRAY;
}
int arguments = args.length;
- Class[] parameterTypes = new Class[arguments];
+ Class<?>[] parameterTypes = new Class[arguments];
for (int i = 0; i < arguments; i++) {
parameterTypes[i] = args[i].getClass();
}
@@ -376,7 +377,7 @@ public class MethodUtils {
Object object,
String methodName,
Object[] args,
- Class[] parameterTypes)
+ Class<?>[] parameterTypes)
throws
NoSuchMethodException,
IllegalAccessException,
@@ -423,10 +424,10 @@ public class MethodUtils {
* @since 1.8.0
*/
public static Object invokeExactStaticMethod(
- Class objectClass,
+ Class<?> objectClass,
String methodName,
Object[] args,
- Class[] parameterTypes)
+ Class<?>[] parameterTypes)
throws
NoSuchMethodException,
IllegalAccessException,
@@ -481,7 +482,7 @@ public class MethodUtils {
* @since 1.8.0
*/
public static Object invokeStaticMethod(
- Class objectClass,
+ Class<?> objectClass,
String methodName,
Object arg)
throws
@@ -524,7 +525,7 @@ public class MethodUtils {
* @since 1.8.0
*/
public static Object invokeStaticMethod(
- Class objectClass,
+ Class<?> objectClass,
String methodName,
Object[] args)
throws
@@ -536,7 +537,7 @@ public class MethodUtils {
args = EMPTY_OBJECT_ARRAY;
}
int arguments = args.length;
- Class[] parameterTypes = new Class[arguments];
+ Class<?>[] parameterTypes = new Class[arguments];
for (int i = 0; i < arguments; i++) {
parameterTypes[i] = args[i].getClass();
}
@@ -573,10 +574,10 @@ public class MethodUtils {
* @since 1.8.0
*/
public static Object invokeStaticMethod(
- Class objectClass,
+ Class<?> objectClass,
String methodName,
Object[] args,
- Class[] parameterTypes)
+ Class<?>[] parameterTypes)
throws
NoSuchMethodException,
IllegalAccessException,
@@ -623,7 +624,7 @@ public class MethodUtils {
* @since 1.8.0
*/
public static Object invokeExactStaticMethod(
- Class objectClass,
+ Class<?> objectClass,
String methodName,
Object arg)
throws
@@ -656,7 +657,7 @@ public class MethodUtils {
* @since 1.8.0
*/
public static Object invokeExactStaticMethod(
- Class objectClass,
+ Class<?> objectClass,
String methodName,
Object[] args)
throws
@@ -668,7 +669,7 @@ public class MethodUtils {
args = EMPTY_OBJECT_ARRAY;
}
int arguments = args.length;
- Class[] parameterTypes = new Class[arguments];
+ Class<?>[] parameterTypes = new Class[arguments];
for (int i = 0; i < arguments; i++) {
parameterTypes[i] = args[i].getClass();
}
@@ -697,11 +698,11 @@ public class MethodUtils {
* @return The accessible method
*/
public static Method getAccessibleMethod(
- Class clazz,
+ Class<?> clazz,
String methodName,
- Class parameterType) {
+ Class<?> parameterType) {
- Class[] parameterTypes = {parameterType};
+ Class<?>[] parameterTypes = {parameterType};
return getAccessibleMethod(clazz, methodName, parameterTypes);
}
@@ -719,9 +720,9 @@ public class MethodUtils {
* @return The accessible method
*/
public static Method getAccessibleMethod(
- Class clazz,
+ Class<?> clazz,
String methodName,
- Class[] parameterTypes) {
+ Class<?>[] parameterTypes) {
try {
MethodDescriptor md = new MethodDescriptor(clazz, methodName, parameterTypes, true);
@@ -770,7 +771,7 @@ public class MethodUtils {
* @return The accessible method
* @since 1.8.0
*/
- public static Method getAccessibleMethod(Class clazz, Method method) {
+ public static Method getAccessibleMethod(Class<?> clazz, Method method) {
// Make sure we have a method to check
if (method == null) {
@@ -802,7 +803,7 @@ public class MethodUtils {
}
String methodName = method.getName();
- Class[] parameterTypes = method.getParameterTypes();
+ Class<?>[] parameterTypes = method.getParameterTypes();
// Check the implemented interfaces and subinterfaces
method =
@@ -833,9 +834,9 @@ public class MethodUtils {
* @param parameterTypes The parameter type signatures
*/
private static Method getAccessibleMethodFromSuperclass
- (Class clazz, String methodName, Class[] parameterTypes) {
+ (Class<?> clazz, String methodName, Class<?>[] parameterTypes) {
- Class parentClazz = clazz.getSuperclass();
+ Class<?> parentClazz = clazz.getSuperclass();
while (parentClazz != null) {
if (Modifier.isPublic(parentClazz.getModifiers())) {
try {
@@ -864,7 +865,7 @@ public class MethodUtils {
* @param parameterTypes The parameter type signatures
*/
private static Method getAccessibleMethodFromInterfaceNest
- (Class clazz, String methodName, Class[] parameterTypes) {
+ (Class<?> clazz, String methodName, Class<?>[] parameterTypes) {
Method method = null;
@@ -872,7 +873,7 @@ public class MethodUtils {
for (; clazz != null; clazz = clazz.getSuperclass()) {
// Check the implemented interfaces of the parent class
- Class[] interfaces = clazz.getInterfaces();
+ Class<?>[] interfaces = clazz.getInterfaces();
for (int i = 0; i < interfaces.length; i++) {
// Is this interface public?
@@ -917,7 +918,7 @@ public class MethodUtils {
* In other words, it finds a method with the given name
* that will take the parameters given.<p>
*
- * <p>This method is slightly undeterminstic since it loops
+ * <p>This method is slightly undeterministic since it loops
* through methods names and return the first matching method.</p>
*
* <p>This method is used by
@@ -934,9 +935,9 @@ public class MethodUtils {
* @return The accessible method
*/
public static Method getMatchingAccessibleMethod(
- Class clazz,
+ Class<?> clazz,
String methodName,
- Class[] parameterTypes) {
+ Class<?>[] parameterTypes) {
// trace logging
Log log = LogFactory.getLog(MethodUtils.class);
if (log.isTraceEnabled()) {
@@ -981,7 +982,7 @@ public class MethodUtils {
}
// compare parameters
- Class[] methodsParams = methods[i].getParameterTypes();
+ Class<?>[] methodsParams = methods[i].getParameterTypes();
int methodParamSize = methodsParams.length;
if (methodParamSize == paramSize) {
boolean match = true;
@@ -1094,11 +1095,11 @@ public class MethodUtils {
* @param destArgs The destination arguments
* @return The total transformation cost
*/
- private static float getTotalTransformationCost(Class[] srcArgs, Class[] destArgs) {
+ private static float getTotalTransformationCost(Class<?>[] srcArgs, Class<?>[] destArgs) {
float totalCost = 0.0f;
for (int i = 0; i < srcArgs.length; i++) {
- Class srcClass, destClass;
+ Class<?> srcClass, destClass;
srcClass = srcArgs[i];
destClass = destArgs[i];
totalCost += getObjectTransformationCost(srcClass, destClass);
@@ -1115,11 +1116,11 @@ public class MethodUtils {
* @param destClass The destination class
* @return The cost of transforming an object
*/
- private static float getObjectTransformationCost(Class srcClass, Class destClass) {
+ private static float getObjectTransformationCost(Class<?> srcClass, Class<?> destClass) {
float cost = 0.0f;
while (srcClass != null && !destClass.equals(srcClass)) {
if (destClass.isPrimitive()) {
- Class destClassWrapperClazz = getPrimitiveWrapper(destClass);
+ Class<?> destClassWrapperClazz = getPrimitiveWrapper(destClass);
if (destClassWrapperClazz != null && destClassWrapperClazz.equals(srcClass)) {
cost += 0.25f;
break;
@@ -1164,9 +1165,9 @@ public class MethodUtils {
* @param parameterType the type of parameter accepted by the method
* @param parameterization the type of parameter being tested
*
- * @return true if the assignement is compatible.
+ * @return true if the assignment is compatible.
*/
- public static final boolean isAssignmentCompatible(Class parameterType, Class parameterization) {
+ public static final boolean isAssignmentCompatible(Class<?> parameterType, Class<?> parameterization) {
// try plain assignment
if (parameterType.isAssignableFrom(parameterization)) {
return true;
@@ -1175,7 +1176,7 @@ public class MethodUtils {
if (parameterType.isPrimitive()) {
// this method does *not* do widening - you must specify exactly
// is this the right behaviour?
- Class parameterWrapperClazz = getPrimitiveWrapper(parameterType);
+ Class<?> parameterWrapperClazz = getPrimitiveWrapper(parameterType);
if (parameterWrapperClazz != null) {
return parameterWrapperClazz.equals(parameterization);
}
@@ -1191,7 +1192,7 @@ public class MethodUtils {
* @return the wrapper type associated with the given primitive
* or null if no match is found
*/
- public static Class getPrimitiveWrapper(Class primitiveType) {
+ public static Class<?> getPrimitiveWrapper(Class<?> primitiveType) {
// does anyone know a better strategy than comparing names?
if (boolean.class.equals(primitiveType)) {
return Boolean.class;
@@ -1222,7 +1223,7 @@ public class MethodUtils {
* @return the primitive type class corresponding to the given wrapper class,
* null if no match is found
*/
- public static Class getPrimitiveType(Class wrapperType) {
+ public static Class<?> getPrimitiveType(Class<?> wrapperType) {
// does anyone know a better strategy than comparing names?
if (Boolean.class.equals(wrapperType)) {
return boolean.class;
@@ -1255,9 +1256,9 @@ public class MethodUtils {
* @param clazz the class to find a representation for, not null
* @return the original class if it not a primitive. Otherwise the wrapper class. Not null
*/
- public static Class toNonPrimitiveClass(Class clazz) {
+ public static Class<?> toNonPrimitiveClass(Class<?> clazz) {
if (clazz.isPrimitive()) {
- Class primitiveClazz = MethodUtils.getPrimitiveWrapper(clazz);
+ Class<?> primitiveClazz = MethodUtils.getPrimitiveWrapper(clazz);
// the above method returns
if (primitiveClazz != null) {
return primitiveClazz;
@@ -1278,9 +1279,9 @@ public class MethodUtils {
*/
private static Method getCachedMethod(MethodDescriptor md) {
if (CACHE_METHODS) {
- Reference methodRef = (Reference)cache.get(md);
+ Reference<Method> methodRef = cache.get(md);
if (methodRef != null) {
- return (Method)methodRef.get();
+ return methodRef.get();
}
}
return null;
@@ -1295,7 +1296,7 @@ public class MethodUtils {
private static void cacheMethod(MethodDescriptor md, Method method) {
if (CACHE_METHODS) {
if (method != null) {
- cache.put(md, new WeakReference(method));
+ cache.put(md, new WeakReference<Method>(method));
}
}
}
@@ -1304,9 +1305,9 @@ public class MethodUtils {
* Represents the key to looking up a Method by reflection.
*/
private static class MethodDescriptor {
- private final Class cls;
+ private final Class<?> cls;
private final String methodName;
- private final Class[] paramTypes;
+ private final Class<?>[] paramTypes;
private final boolean exact;
private final int hashCode;
@@ -1315,10 +1316,10 @@ public class MethodUtils {
*
* @param cls the class to reflect, must not be null
* @param methodName the method name to obtain
- * @param paramTypes the array of classes representing the paramater types
+ * @param paramTypes the array of classes representing the parameter types
* @param exact whether the match has to be exact.
*/
- public MethodDescriptor(Class cls, String methodName, Class[] paramTypes, boolean exact) {
+ public MethodDescriptor(Class<?> cls, String methodName, Class<?>[] paramTypes, boolean exact) {
if (cls == null) {
throw new IllegalArgumentException("Class cannot be null");
}
Modified: commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/MutableDynaClass.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/MutableDynaClass.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/MutableDynaClass.java (original)
+++ commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/MutableDynaClass.java Fri Nov 8 21:08:30 2013
@@ -60,7 +60,7 @@ public interface MutableDynaClass extend
* @exception IllegalStateException if this DynaClass is currently
* restricted, so no new properties can be added
*/
- public void add(String name, Class type);
+ public void add(String name, Class<?> type);
/**
@@ -79,7 +79,7 @@ public interface MutableDynaClass extend
* @exception IllegalStateException if this DynaClass is currently
* restricted, so no new properties can be added
*/
- public void add(String name, Class type, boolean readable,
+ public void add(String name, Class<?> type, boolean readable,
boolean writeable);
Modified: commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/PropertyUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/PropertyUtils.java?rev=1540186&r1=1540185&r2=1540186&view=diff
==============================================================================
--- commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/PropertyUtils.java (original)
+++ commons/proper/beanutils/trunk/src/main/java/org/apache/commons/beanutils/PropertyUtils.java Fri Nov 8 21:08:30 2013
@@ -203,7 +203,7 @@ public class PropertyUtils {
* propety cannot be found
* @see PropertyUtilsBean#describe
*/
- public static Map describe(Object bean)
+ public static Map<String, Object> describe(Object bean)
throws IllegalAccessException, InvocationTargetException,
NoSuchMethodException {
@@ -344,7 +344,7 @@ public class PropertyUtils {
* @deprecated This method should not be exposed
*/
@Deprecated
- public static FastHashMap getMappedPropertyDescriptors(Class beanClass) {
+ public static FastHashMap getMappedPropertyDescriptors(Class<?> beanClass) {
return PropertyUtilsBean.getInstance().getMappedPropertyDescriptors(beanClass);
@@ -478,7 +478,7 @@ public class PropertyUtils {
* @see PropertyUtilsBean#getPropertyDescriptors(Class)
*/
public static PropertyDescriptor[]
- getPropertyDescriptors(Class beanClass) {
+ getPropertyDescriptors(Class<?> beanClass) {
return PropertyUtilsBean.getInstance().getPropertyDescriptors(beanClass);
@@ -527,7 +527,7 @@ public class PropertyUtils {
* propety cannot be found
* @see PropertyUtilsBean#getPropertyEditorClass(Object,String)
*/
- public static Class getPropertyEditorClass(Object bean, String name)
+ public static Class<?> getPropertyEditorClass(Object bean, String name)
throws IllegalAccessException, InvocationTargetException,
NoSuchMethodException {
@@ -560,7 +560,7 @@ public class PropertyUtils {
* propety cannot be found
* @see PropertyUtilsBean#getPropertyType(Object, String)
*/
- public static Class getPropertyType(Object bean, String name)
+ public static Class<?> getPropertyType(Object bean, String name)
throws IllegalAccessException, InvocationTargetException,
NoSuchMethodException {