Merging from -r468106:814127 of collections_jdk5_branch - namely where this code was generified; mostly in r738956.
Also see the following revisions: ------------------------------------------------------------------------ r570378 | skestle | 2007-08-28 04:03:40 -0700 (Tue, 28 Aug 2007) | 1 line Generified InstantiateFactory ------------------------------------------------------------------------ git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@815049 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b9db60ade4
commit
11f0510299
|
@ -31,19 +31,19 @@ import org.apache.commons.collections.FunctorException;
|
||||||
*
|
*
|
||||||
* @author Stephen Colebourne
|
* @author Stephen Colebourne
|
||||||
*/
|
*/
|
||||||
public class InstantiateFactory implements Factory, Serializable {
|
public class InstantiateFactory<T> implements Factory<T>, Serializable {
|
||||||
|
|
||||||
/** The serial version */
|
/** The serial version */
|
||||||
private static final long serialVersionUID = -7732226881069447957L;
|
private static final long serialVersionUID = -7732226881069447957L;
|
||||||
|
|
||||||
/** The class to create */
|
/** The class to create */
|
||||||
private final Class iClassToInstantiate;
|
private final Class<T> iClassToInstantiate;
|
||||||
/** The constructor parameter types */
|
/** The constructor parameter types */
|
||||||
private final Class[] iParamTypes;
|
private final Class<?>[] iParamTypes;
|
||||||
/** The constructor arguments */
|
/** The constructor arguments */
|
||||||
private final Object[] iArgs;
|
private final Object[] iArgs;
|
||||||
/** The constructor */
|
/** The constructor */
|
||||||
private transient Constructor iConstructor = null;
|
private transient Constructor<T> iConstructor = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory method that performs validation.
|
* Factory method that performs validation.
|
||||||
|
@ -53,7 +53,7 @@ public class InstantiateFactory implements Factory, Serializable {
|
||||||
* @param args the constructor arguments
|
* @param args the constructor arguments
|
||||||
* @return a new instantiate factory
|
* @return a new instantiate factory
|
||||||
*/
|
*/
|
||||||
public static Factory getInstance(Class classToInstantiate, Class[] paramTypes, Object[] args) {
|
public static <T> Factory<T> getInstance(Class<T> classToInstantiate, Class<?>[] paramTypes, Object[] args) {
|
||||||
if (classToInstantiate == null) {
|
if (classToInstantiate == null) {
|
||||||
throw new IllegalArgumentException("Class to instantiate must not be null");
|
throw new IllegalArgumentException("Class to instantiate must not be null");
|
||||||
}
|
}
|
||||||
|
@ -64,12 +64,11 @@ public class InstantiateFactory implements Factory, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (paramTypes == null || paramTypes.length == 0) {
|
if (paramTypes == null || paramTypes.length == 0) {
|
||||||
return new InstantiateFactory(classToInstantiate);
|
return new InstantiateFactory<T>(classToInstantiate);
|
||||||
} else {
|
|
||||||
paramTypes = (Class[]) paramTypes.clone();
|
|
||||||
args = (Object[]) args.clone();
|
|
||||||
return new InstantiateFactory(classToInstantiate, paramTypes, args);
|
|
||||||
}
|
}
|
||||||
|
paramTypes = paramTypes.clone();
|
||||||
|
args = args.clone();
|
||||||
|
return new InstantiateFactory<T>(classToInstantiate, paramTypes, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,7 +77,7 @@ public class InstantiateFactory implements Factory, Serializable {
|
||||||
*
|
*
|
||||||
* @param classToInstantiate the class to instantiate
|
* @param classToInstantiate the class to instantiate
|
||||||
*/
|
*/
|
||||||
public InstantiateFactory(Class classToInstantiate) {
|
public InstantiateFactory(Class<T> classToInstantiate) {
|
||||||
super();
|
super();
|
||||||
iClassToInstantiate = classToInstantiate;
|
iClassToInstantiate = classToInstantiate;
|
||||||
iParamTypes = null;
|
iParamTypes = null;
|
||||||
|
@ -94,7 +93,7 @@ public class InstantiateFactory implements Factory, Serializable {
|
||||||
* @param paramTypes the constructor parameter types, not cloned
|
* @param paramTypes the constructor parameter types, not cloned
|
||||||
* @param args the constructor arguments, not cloned
|
* @param args the constructor arguments, not cloned
|
||||||
*/
|
*/
|
||||||
public InstantiateFactory(Class classToInstantiate, Class[] paramTypes, Object[] args) {
|
public InstantiateFactory(Class<T> classToInstantiate, Class<?>[] paramTypes, Object[] args) {
|
||||||
super();
|
super();
|
||||||
iClassToInstantiate = classToInstantiate;
|
iClassToInstantiate = classToInstantiate;
|
||||||
iParamTypes = paramTypes;
|
iParamTypes = paramTypes;
|
||||||
|
@ -119,7 +118,7 @@ public class InstantiateFactory implements Factory, Serializable {
|
||||||
*
|
*
|
||||||
* @return the new object
|
* @return the new object
|
||||||
*/
|
*/
|
||||||
public Object create() {
|
public T create() {
|
||||||
// needed for post-serialization
|
// needed for post-serialization
|
||||||
if (iConstructor == null) {
|
if (iConstructor == null) {
|
||||||
findConstructor();
|
findConstructor();
|
||||||
|
@ -127,7 +126,6 @@ public class InstantiateFactory implements Factory, Serializable {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return iConstructor.newInstance(iArgs);
|
return iConstructor.newInstance(iArgs);
|
||||||
|
|
||||||
} catch (InstantiationException ex) {
|
} catch (InstantiationException ex) {
|
||||||
throw new FunctorException("InstantiateFactory: InstantiationException", ex);
|
throw new FunctorException("InstantiateFactory: InstantiationException", ex);
|
||||||
} catch (IllegalAccessException ex) {
|
} catch (IllegalAccessException ex) {
|
||||||
|
|
Loading…
Reference in New Issue