org.robobinding.property.PropertyDescriptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of robobinding Show documentation
Show all versions of robobinding Show documentation
A Presentation Model(MVVM) framework for the Android platform
The newest version!
package org.robobinding.property;
import java.text.MessageFormat;
import java.util.Collections;
import java.util.Set;
import org.robobinding.util.Joiner;
/**
* @since 1.0
* @author Cheng Wei
*
*/
public class PropertyDescriptor {
private Class> beanType;
private Class> propertyType;
private String name;
private boolean readable;
private boolean writable;
public PropertyDescriptor(Class> beanType, Class> propertyType, String name, boolean readable, boolean writable) {
this.beanType = beanType;
this.propertyType = propertyType;
this.name = name;
this.readable = readable;
this.writable = writable;
}
public Class> getPropertyType() {
return propertyType;
}
public String getName() {
return name;
}
public void checkReadWriteProperty(boolean isReadWriteProperty) {
checkReadable();
if (isReadWriteProperty) {
checkWritable();
}
}
private void checkReadable() {
if (!readable) {
throw new RuntimeException("The property " + getShortDescription() + " is not readable");
}
}
private void checkWritable() {
if (!writable) {
throw new RuntimeException("The property " + getShortDescription() + " is not writable");
}
}
public String getShortDescription() {
return PropertyUtils.shortDescription(beanType, name);
}
public String getDescription() {
return decriptionWithDependencies(Collections.emptySet());
}
public String decriptionWithDependencies(Set dependentProperties) {
String description = MessageFormat.format(
"property(name:{0}, propertyType:{1}, isReadable:{2}, isWritable:{3}, beanType:{4}",
name, propertyType.getName(), readable, writable, beanType.getName());
if (!dependentProperties.isEmpty()) {
description += MessageFormat.format(", dependencies:{0}", Joiner.on(",").join(dependentProperties));
}
description += ")";
return description;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy