| Constructor and Description |
|---|
Type(Class<?> type) |
Type(Class<?> type,
BeanNamingStrategy naming,
BeanPropertyOrderingStrategy orderBy) |
| Modifier and Type | Method and Description |
|---|---|
List<ImmutableTypeProperty> |
accessorList()
Return a list of the accessors exposed on this type
|
String |
camelName()
Return the name of the type using camel notation.
|
String |
canonicalName()
Return the full name of the type.
|
String |
componentName()
Return the name for the
Class.getComponentType(), For a scalar Class this returns the same as canonicalName() but for an array it this return the class
simple name but without the []. |
String |
componentSimpleName()
Return the simple name for the
Class.getComponentType(), For a scalar Class this returns the same as simpleName() but for an array it this return the class
simple name but without the []. |
TypeProperty |
get(String name)
Get the requested property from the type or return
null if the property is not present. |
Method |
getAccessor(String name)
Return the accessor Method for the given property.
|
Class<?> |
getType()
Return the
Class for this type |
boolean |
hasProperty(String name)
Test if the supplied type has a property with the given name.
|
boolean |
is(Class<?> otherType)
Return
true if this type is the same type or a subclass of the other type. |
boolean |
isArray()
Return
true if this type is an array |
boolean |
isEnum()
Return
true if this type is a Java enumeration |
boolean |
isPrimitive()
Return
true if this type is a primitive type |
boolean |
isPropertyType(String name,
Class<?> type)
Test if the property on the type is of the supplied type.
|
String |
packageName()
Return the package name for this type.
|
List<TypeProperty> |
propertyList()
Return a list of the publicly exposes get/set properties on a class.
|
Map<String,TypeProperty> |
propertyMap()
Return a map of the publicly exposes get/set properties on the type with the property name as the key and the initial character lowercased For example:
|
TypeProperty |
propertyNamed(String propertyName)
Get the requested property from the type or return
null if the property is not present. |
Class<?> |
propertyType(String name)
Return the property type on the type for the supplied property name or
null if the property doesn't exist. |
String |
simpleName()
Return the name of the type without any package information.
|
Class<?>[] |
superTypes()
Return this type's super types as an array of
Class instances |
String |
toString() |
static Type |
type(Class<?> type) |
static Type |
type(Class<?> type,
BeanNamingStrategy naming) |
static Type |
type(Object instance) |
static Type |
type(Object instance,
BeanNamingStrategy naming) |
Class<?>[] |
typeHierachy()
Return this type and it's super types as an array of
Class instances |
static TypeProperty |
typeProperty(Class<?> instance,
String name)
Static factory method for constructing a
TypeProperty for the property name on the given class. |
void |
visit(TypeVisitor visitor)
Visit the supplied class and notify the visitor for each bean property found.
|
public Type(Class<?> type)
public Type(Class<?> type, BeanNamingStrategy naming, BeanPropertyOrderingStrategy orderBy)
public static Type type(Class<?> type, BeanNamingStrategy naming)
public static Type type(Object instance, BeanNamingStrategy naming)
public static final TypeProperty typeProperty(Class<?> instance, String name)
TypeProperty for the property name on the given class.public String camelName()
Typedmy.package.MyObject would have the camelName myObject.public String simpleName()
Typedmy.package.MyObject would have the name MyObject.simpleName in interface Typedpublic String componentName()
Class.getComponentType(), For a scalar Class this returns the same as canonicalName() but for an array it this return the class
simple name but without the [].public String componentSimpleName()
Class.getComponentType(), For a scalar Class this returns the same as simpleName() but for an array it this return the class
simple name but without the [].public String canonicalName()
Typedmy.package.MyObject would have the name my.package.MyObject.canonicalName in interface Typedpublic boolean hasProperty(String name)
if ( type(MyObject.class).hasProperty("surname"))) {
// Do Something;
}
name - the property namepublic boolean isPropertyType(String name, Class<?> type)
if (bean(MyObject.class).isPropertyType("surname", String.class)) {
// Do something
}
name - the property nametype - the expected type of the propertypublic void visit(TypeVisitor visitor)
type(MyObject.class).visit(new TypeVisitor() {
public void visit(final TypeProperty property) {
System.out.println(property.getName());
}
});
type - the type to get the property fromvisitor - the visitor which will be notified of every bean property encounteredpublic List<TypeProperty> propertyList()
List<TypeProperty> properties = Type.type(MyObject.class).propertyList()
public List<ImmutableTypeProperty> accessorList()
public Map<String,TypeProperty> propertyMap()
Map<String, BeanProperty> propertyMap = Bean.bean(MyObject.class).propertyMap()
public TypeProperty propertyNamed(String propertyName)
null if the property is not present. For example:
TypeProperty surname = type(MyObject.class).propertyNamed(MyObject.class, "surname")
name - the property namepublic TypeProperty get(String name)
null if the property is not present. For example:
TypeProperty surname = type(MyObject.class).get("surname")
name - the property namepublic Class<?> propertyType(String name)
null if the property doesn't exist. For example:
if (String.class.equals(type(MyObject.class).propertyType("surname"))) {
// Do something
}
name - the property namepublic Method getAccessor(String name)
Method method = type(MyObject).getAccessor("surname")
name - the property nameBeanPropertyNotFoundException - if the property is not foundpublic Class<?>[] typeHierachy()
TypedClass instancestypeHierachy in interface Typedpublic Class<?>[] superTypes()
TypedClass instancessuperTypes in interface Typedpublic boolean is(Class<?> otherType)
true if this type is the same type or a subclass of the other type.public boolean isArray()
Typedtrue if this type is an arraypublic String packageName()
Typedmy.package.MyObject would have the name my.packagepackageName in interface Typedpublic boolean isPrimitive()
Typedtrue if this type is a primitive typeisPrimitive in interface Typedpublic boolean isEnum()
Typedtrue if this type is a Java enumerationpublic Class<?> getType()
TypedClass for this typeCopyright © 2015. All rights reserved.