moved static factory methods up

This commit is contained in:
Keith Donald 2009-12-15 18:50:17 +00:00
parent d6f4f4c7b4
commit 39325958bc
1 changed files with 27 additions and 28 deletions

View File

@ -354,6 +354,32 @@ public class TypeDescriptor {
return isTypeAssignableTo(targetType.getType()); return isTypeAssignableTo(targetType.getType());
} }
// static factory methods
/**
* Creates a new type descriptor for the given class.
* @param type the class
* @return the type descriptor
*/
public static TypeDescriptor valueOf(Class<?> type) {
if (type == null) {
return TypeDescriptor.NULL;
} else if (type.equals(String.class)) {
return TypeDescriptor.STRING;
} else {
return new TypeDescriptor(type);
}
}
/**
* Creates a new type descriptor for the class of the given object.
* @param object the object
* @return the type descriptor
*/
public static TypeDescriptor forObject(Object object) {
return (object == null ? NULL : valueOf(object.getClass()));
}
// internal helpers // internal helpers
private Class<?> getArrayComponentType() { private Class<?> getArrayComponentType() {
@ -438,32 +464,5 @@ public class TypeDescriptor {
return builder.toString(); return builder.toString();
} }
} }
// static factory methods
/**
* Creates a new type descriptor for the given class.
* @param type the class
* @return the type descriptor
*/
public static TypeDescriptor valueOf(Class<?> type) {
if (type == null) {
return TypeDescriptor.NULL;
} else if (type.equals(String.class)) {
return TypeDescriptor.STRING;
} else {
return new TypeDescriptor(type);
}
}
/**
* Creates a new type descriptor for the class of the given object.
* @param object the object
* @return the type descriptor
*/
public static TypeDescriptor forObject(Object object) {
return (object == null ? NULL : valueOf(object.getClass()));
}
} }