| Modifier | Constructor and Description |
|---|---|
protected |
Instance(InstanceInspector inspector,
Object instance,
BeanNamingStrategy naming) |
| Modifier and Type | Method and Description |
|---|---|
void |
apply(BeanPropertyFunction function)
Apply the
BeanPropertyFunction to all properties on the supplied instance. |
void |
apply(BeanPropertyFunction function,
BeanPropertyPredicate predicate)
Apply the
BeanPropertyFunction to all properties which match the predicate in the supplied instances. |
void |
dump(OutputStream os)
Write out all properties and their values on this object.
|
void |
dump(StringBuffer buffer)
Write out all properties and their values on this object.
|
void |
dump(Writer writer)
Write out all properties and their values on this object.
|
List<BeanProperty> |
find(BeanPropertyPredicate predicate)
Find all property properties which match the predicate.
|
BeanProperty |
findAny(BeanPropertyPredicate predicate)
Find the first instance of the property which matches the given predicate in the instance.
|
BeanProperty |
get(BeanPropertyPredicate predicate)
Get the property which matches the predicate from the instance or return
null if not matching property is found. |
BeanProperty |
get(String name)
Get the requested property from the type or return
null if the property is not present. |
boolean |
hasProperty(BeanPropertyPredicate predicate)
Test if the supplied instance has a Bean property which matches the given predicate.
|
boolean |
hasProperty(String name)
Test if the supplied instance has a Bean property with the given name.
|
boolean |
hasProperty(String name,
Object value)
Test if the supplied instance has a Bean property with the given name and value.
|
boolean |
isPropertyType(BeanPropertyPredicate predicate,
Class<?> type)
Test if the property which matches the predicate on the supplied instance is of the supplied type.
|
boolean |
isPropertyType(String name,
Class<?> type)
Test if the property on the supplied instance is of the supplied type.
|
List<BeanProperty> |
propertyList()
Return a list of the publicly exposes get/set properties on this instance.
|
Map<String,BeanProperty> |
propertyMap()
Return a map of the publicly exposes get/set properties on the Bean with the property name as the key and the initial character lowercased For example:
|
BeanProperty |
propertyNamed(String name)
Get the requested property from the instance or return
null if the property is not present. |
Class<?> |
propertyType(BeanPropertyPredicate predicate)
Return the property type on the instance for the first property which matches the supplied predicate or
null if no matching properties are found. |
Class<?> |
propertyType(String name)
Return the property type on the instance for the supplied property name or
null if the property doesn't exist. |
Object |
propertyValue(BeanPropertyPredicate predicate)
Return the first property value on the instance which matches the predicate or return
null if the no matching properties are not present on the instance. |
<T> T |
propertyValue(BeanPropertyPredicate predicate,
Class<T> type)
Return the first property value on the instance which matches the predicate or return
null if the no matching properties are not present on the instance. |
Object |
propertyValue(String name)
Return the property value on the instance for the supplied property name or return
null if the property is not present on the instance. |
<T> T |
propertyValue(String name,
Class<T> type)
Return the property value on the instance for the supplied property name or return
null if the property is not present on the instance. |
void |
setNamingStrategy(BeanNamingStrategy naming)
Override the default naming strategy
|
void |
setProperty(BeanPropertyPredicate predicate,
Object value)
Set the property which matches the predicate on the given instance.
|
boolean |
setProperty(String name,
Object value)
Set the requested property on the given instance.
|
void |
visit(BeanVisitor visitor)
Visit the supplied bean or graph instance and notify the visitor for each bean property found.
|
protected Instance(InstanceInspector inspector, Object instance, BeanNamingStrategy naming)
public List<BeanProperty> propertyList()
List<BeanPropertyInstance> properties = bean(myObject).propertyList()
public Map<String,BeanProperty> propertyMap()
Map<String, BeanPropertyInstance> propertyMap = bean(myObject).propertyMap()
public void setProperty(BeanPropertyPredicate predicate, Object value)
bean(myObject).setProperty(BeanPredicates.named("surname"), "Smith")
predicate - a predicate to match the propertiesvalue - the property valuepublic Object propertyValue(BeanPropertyPredicate predicate)
null if the no matching properties are not present on the instance. For
example:
Object value = bean(myObject).propertyValue(BeanPredicates.named("surname")))
instance - an object to get the property fromname - the property namepublic <T> T propertyValue(BeanPropertyPredicate predicate, Class<T> type)
null if the no matching properties are not present on the instance. For
example:
String value = bean(myObject).propertyValue(BeanPredicates.named("surname")), String.class)
predicate - a predicate to match the propertiestype - the type to return the property value aspublic Object propertyValue(String name)
null if the property is not present on the instance. For example:
Object value = bean(myObject).propertyValue("surname"))
name - the property namepublic <T> T propertyValue(String name, Class<T> type)
null if the property is not present on the instance. For example:
String value = bean(myObject).propertyValue("surname", String.class))
name - the property nametype - the type to return the property value aspublic boolean hasProperty(BeanPropertyPredicate predicate)
if ( bean(myObject).hasProperty(aUser, BeanPredicates.named("surname")))) {
// Do Something
}
predicate - the predicate to select the property withpublic BeanProperty get(String name)
null if the property is not present. For example:
BeanPropertyInstance surname = bean(myObject).get("surname")
name - the property namepublic BeanProperty get(BeanPropertyPredicate predicate)
null if not matching property is found. For example:
BeanPropertyInstance surname = bean(myObject).get(BeanPredicates.named("surname"))
predicate - a predicate to match the propertypublic BeanProperty propertyNamed(String name)
null if the property is not present. For example:
BeanPropertyInstance surname = bean(myObject).propertyNamed("surname")
name - the property namepublic Class<?> propertyType(String name)
null if the property doesn't exist. For example:
if (String.class.equals(bean(myObject).propertyType("surname"))) {
// Do something
}
name - the property namepublic Class<?> propertyType(BeanPropertyPredicate predicate)
null if no matching properties are found. For
example:
if (String.class.equals(bean(myObject).propertyType(BeanPredicates.named("surname")))) {
// Do something
}
predicate - a predicate to match the propertiespublic BeanProperty findAny(BeanPropertyPredicate predicate)
BeanPropertyInstance property = bean(myObject).findAny(BeanPredicates.withValue("name" "Bob"))
predicate - a predicate to match the propertiespublic void apply(BeanPropertyFunction function)
BeanPropertyFunction to all properties on the supplied instance. For example
bean(myObject).apply(BeanFunctions.setValue(null))
function - the function to apply to the matching propertiespublic void apply(BeanPropertyFunction function, BeanPropertyPredicate predicate)
BeanPropertyFunction to all properties which match the predicate in the supplied instances. For example
bean(myObject).apply(BeanPredicates.ofType(String.class), BeanFunctions.setValue(null))
function - the function to apply to the matching propertiespredicate - a predicate to match the propertiespublic List<BeanProperty> find(BeanPropertyPredicate predicate)
for ( BeanPropertyInstance property : bean(myObject).find(BeanPredicates.ofType(String.class)) {
property.setValue(null);
}
predicate - a predicate to match the propertiespublic void visit(BeanVisitor visitor)
bean(myObject).visit(new BeanVisitor() {
public void visit(final BeanPropertyInstance property, final Object current, final BeanPropertyPath path, final Object[] stack) {
System.out.println(path.fullPath());
}
});
visitor - the visitor which will be notified of every bean property encounteredpublic boolean hasProperty(String name)
if ( bean(myObject).hasProperty("surname"))) {
// Do Something
}
name - the property namepublic boolean hasProperty(String name, Object value)
if ( bean(myObject).hasProperty("surname","Smith"))) {
// Do Something
}
name - the property namevalue - the value to test forpublic boolean setProperty(String name, Object value)
bean(myObject).setProperty("surname", "Smith")
name - the property namevalue - the property valuepublic boolean isPropertyType(String name, Class<?> type)
if (bean(myObject).isPropertyType("surname", String.class)) {
// Do something
}
name - the property nametype - the expected type of the propertypublic boolean isPropertyType(BeanPropertyPredicate predicate, Class<?> type)
if (bean(myObject).isPropertyType("surname", String.class)) {
// Do something
}
predicate - a predicate to match the propertiestype - the expected type of the propertypublic void setNamingStrategy(BeanNamingStrategy naming)
public void dump(Writer writer)
writer - the writer to write the output topublic void dump(OutputStream os)
os - the stream to write the output topublic void dump(StringBuffer buffer)
buffer - the buffer to append the output toCopyright © 2015. All rights reserved.