本文整理了Java中org.intermine.metadata.Util.decomposeClass()
方法的一些代码示例,展示了Util.decomposeClass()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.decomposeClass()
方法的具体详情如下:
包路径:org.intermine.metadata.Util
类名称:Util
方法名:decomposeClass
[英]Convert a dynamic Class into a Set of Class objects that comprise it.
[中]将动态类转换为组成它的一组类对象。
代码示例来源:origin: intermine/intermine
/**
* Returns true if sup is a superclass of sub (or the same), taking into account dynamic
* classes.
*
* @param sup the supposed superclass
* @param sub the supposed subclass
* @return a boolean
*/
public static boolean isAssignableFrom(Class<?> sup, Class<?> sub) {
Set<Class<?>> classes = Util.decomposeClass(sup);
for (Class<?> clazz : classes) {
if (!clazz.isAssignableFrom(sub)) {
return false;
}
}
return true;
}
代码示例来源:origin: org.intermine/intermine-objectstore
/**
* Returns true if sup is a superclass of sub (or the same), taking into account dynamic
* classes.
*
* @param sup the supposed superclass
* @param sub the supposed subclass
* @return a boolean
*/
public static boolean isAssignableFrom(Class<?> sup, Class<?> sub) {
Set<Class<?>> classes = Util.decomposeClass(sup);
for (Class<?> clazz : classes) {
if (!clazz.isAssignableFrom(sub)) {
return false;
}
}
return true;
}
代码示例来源:origin: org.intermine/intermine-api
private Set<String> getIgnorableFields(FastPathObject obj) {
Set<String> ret = new HashSet<String>();
for (Class<?> clazz: Util.decomposeClass(obj.getClass())) {
if (ignoredFields.containsKey(clazz)) {
ret.addAll(ignoredFields.get(clazz));
}
}
return ret;
}
代码示例来源:origin: intermine/intermine
private Set<String> getIgnorableFields(FastPathObject obj) {
Set<String> ret = new HashSet<String>();
for (Class<?> clazz: Util.decomposeClass(obj.getClass())) {
if (ignoredFields.containsKey(clazz)) {
ret.addAll(ignoredFields.get(clazz));
}
}
return ret;
}
代码示例来源:origin: org.intermine/intermine-api
/**
* Return true if given type (of a constraint) can be assigned to the InterMineObject - i.e.
* if the class or any superclass of the InterMineObject are the type. Type can be a qualified
* or unqualified class name.
*
* @param cls the class in the model that will be assigned to
* @param obj the InterMineObject to check
* @return a boolean
*/
public static boolean canAssignObjectToType(Class<?> cls, InterMineObject obj) {
for (Class<?> c : Util.decomposeClass(obj.getClass())) {
if (cls.isAssignableFrom(c)) {
return true;
}
}
return false;
}
}
代码示例来源:origin: intermine/intermine
/**
* Return true if given type (of a constraint) can be assigned to the InterMineObject - i.e.
* if the class or any superclass of the InterMineObject are the type. Type can be a qualified
* or unqualified class name.
*
* @param cls the class in the model that will be assigned to
* @param obj the InterMineObject to check
* @return a boolean
*/
public static boolean canAssignObjectToType(Class<?> cls, InterMineObject obj) {
for (Class<?> c : Util.decomposeClass(obj.getClass())) {
if (cls.isAssignableFrom(c)) {
return true;
}
}
return false;
}
}
代码示例来源:origin: org.intermine/intermine-model
/**
* Return true if and only if the object is an instance of the class given by the className.
* @param object the object to test
* @param className the super class name to test for
* @return true if object is an instance of className
* @exception ClassNotFoundException if the class given by className cannot be located
*/
public static boolean isInstanceOf(FastPathObject object, String className)
throws ClassNotFoundException {
Set<Class<?>> classes = Util.decomposeClass(object.getClass());
Class<?> testClass = Class.forName(className);
for (Class<?> objectClass: classes) {
if (testClass.isAssignableFrom(objectClass)) {
return true;
}
}
return false;
}
代码示例来源:origin: intermine/intermine
/**
* Return true if and only if the object is an instance of the class given by the className.
* @param object the object to test
* @param className the super class name to test for
* @return true if object is an instance of className
* @exception ClassNotFoundException if the class given by className cannot be located
*/
public static boolean isInstanceOf(FastPathObject object, String className)
throws ClassNotFoundException {
Set<Class<?>> classes = Util.decomposeClass(object.getClass());
Class<?> testClass = Class.forName(className);
for (Class<?> objectClass: classes) {
if (testClass.isAssignableFrom(objectClass)) {
return true;
}
}
return false;
}
代码示例来源:origin: org.intermine/intermine-objectstore
/**
* Returns a String representation.
*
* @return a String representation
*/
@Override
public String toString() {
Set<Class<?>> classes = Util.decomposeClass(type);
if (classes.size() == 1) {
return type.getName();
} else {
boolean needComma = false;
StringBuffer retval = new StringBuffer();
for (Class<?> clazz : classes) {
retval.append(needComma ? ", " : "(");
needComma = true;
retval.append(clazz.getName());
}
return retval.toString() + ")";
}
}
}
代码示例来源:origin: intermine/intermine
/**
* Returns a String representation.
*
* @return a String representation
*/
@Override
public String toString() {
Set<Class<?>> classes = Util.decomposeClass(type);
if (classes.size() == 1) {
return type.getName();
} else {
boolean needComma = false;
StringBuffer retval = new StringBuffer();
for (Class<?> clazz : classes) {
retval.append(needComma ? ", " : "(");
needComma = true;
retval.append(clazz.getName());
}
return retval.toString() + ")";
}
}
}
代码示例来源:origin: intermine/intermine
/**
* Returns the result of decomposeClass if that is a single class, or throws an exception if
* there are more than one.
*
* @param clazz the class
* @return the corresponding non-dynamic class
*/
@SuppressWarnings("unchecked")
public static Class<? extends FastPathObject> getSimpleClass(
Class<? extends FastPathObject> clazz) {
Set<Class<?>> decomposed = Util.decomposeClass(clazz);
if (decomposed.size() > 1) {
throw new IllegalArgumentException("No simple class for "
+ Util.getFriendlyName(clazz));
}
return (Class) decomposed.iterator().next();
}
代码示例来源:origin: org.intermine/intermine-objectstore
/**
* Returns the result of decomposeClass if that is a single class, or throws an exception if
* there are more than one.
*
* @param clazz the class
* @return the corresponding non-dynamic class
*/
@SuppressWarnings("unchecked")
public static Class<? extends FastPathObject> getSimpleClass(
Class<? extends FastPathObject> clazz) {
Set<Class<?>> decomposed = Util.decomposeClass(clazz);
if (decomposed.size() > 1) {
throw new IllegalArgumentException("No simple class for "
+ Util.getFriendlyName(clazz));
}
return (Class) decomposed.iterator().next();
}
代码示例来源:origin: intermine/intermine
/**
* Creates a friendly name for a given class.
*
* @param clazz the class
* @return a String describing the class, without package names
*/
public static synchronized String getFriendlyName(Class<?> clazz) {
String retval = friendlyNameMap.get(clazz);
if (retval == null) {
retval = "";
Iterator<Class<?>> iter = decomposeClass(clazz).iterator();
boolean needComma = false;
while (iter.hasNext()) {
Class<?> constit = iter.next();
retval += needComma ? "," : "";
needComma = true;
retval += constit.getName().substring(constit.getName().lastIndexOf('.') + 1);
}
friendlyNameMap.put(clazz, retval);
}
return retval;
}
代码示例来源:origin: org.intermine/intermine-model
/**
* Creates a friendly name for a given class.
*
* @param clazz the class
* @return a String describing the class, without package names
*/
public static synchronized String getFriendlyName(Class<?> clazz) {
String retval = friendlyNameMap.get(clazz);
if (retval == null) {
retval = "";
Iterator<Class<?>> iter = decomposeClass(clazz).iterator();
boolean needComma = false;
while (iter.hasNext()) {
Class<?> constit = iter.next();
retval += needComma ? "," : "";
needComma = true;
retval += constit.getName().substring(constit.getName().lastIndexOf('.') + 1);
}
friendlyNameMap.put(clazz, retval);
}
return retval;
}
代码示例来源:origin: intermine/intermine
/**
* Returns the simple class name for the given class or throws an exception if
* there are more than one.
* @param clazz the class
* @return the simple class name
*/
public static synchronized String getSimpleClassName(Class<?> clazz) {
String retval = simpleNameMap.get(clazz);
if (retval == null) {
Set<Class<?>> decomposedClass = Util.decomposeClass(clazz);
if (decomposedClass.size() > 1) {
throw new IllegalArgumentException("No simple name for class: "
+ Util.getFriendlyName(clazz));
} else {
retval = decomposedClass.iterator().next().getName();
simpleNameMap.put(clazz, retval);
}
}
return retval;
}
代码示例来源:origin: org.intermine/intermine-objectstore
/**
* Returns the simple class name for the given class or throws an exception if
* there are more than one.
* @param clazz the class
* @return the simple class name
*/
public static synchronized String getSimpleClassName(Class<?> clazz) {
String retval = simpleNameMap.get(clazz);
if (retval == null) {
Set<Class<?>> decomposedClass = Util.decomposeClass(clazz);
if (decomposedClass.size() > 1) {
throw new IllegalArgumentException("No simple name for class: "
+ Util.getFriendlyName(clazz));
} else {
retval = decomposedClass.iterator().next().getName();
simpleNameMap.put(clazz, retval);
}
}
return retval;
}
代码示例来源:origin: intermine/intermine
Set<Class<?>> classes = Util.decomposeClass(type);
StringBuffer retval = new StringBuffer();
if (osb != null) {
代码示例来源:origin: org.intermine/intermine-api
private Vector<ClassAttributes> getClassAttributes(Model model, Class<?> baseClass) {
Vector<ClassAttributes> attributes = decomposedClassesCache.get(baseClass);
if (attributes == null) {
LOG.info("decomposedClassesCache: No entry for " + baseClass + ", adding...");
attributes = new Vector<ClassAttributes>();
for (Class<?> cls : Util.decomposeClass(baseClass)) {
ClassDescriptor cld = model.getClassDescriptorByName(cls.getName());
attributes.add(new ClassAttributes(cld.getUnqualifiedName(), cld
.getAllAttributeDescriptors()));
}
decomposedClassesCache.put(baseClass, attributes);
}
return attributes;
}
代码示例来源:origin: intermine/intermine
private Vector<ClassAttributes> getClassAttributes(Model model, Class<?> baseClass) {
Vector<ClassAttributes> attributes = decomposedClassesCache.get(baseClass);
if (attributes == null) {
LOG.info("decomposedClassesCache: No entry for " + baseClass + ", adding...");
attributes = new Vector<ClassAttributes>();
for (Class<?> cls : Util.decomposeClass(baseClass)) {
ClassDescriptor cld = model.getClassDescriptorByName(cls.getName());
attributes.add(new ClassAttributes(cld.getUnqualifiedName(), cld
.getAllAttributeDescriptors()));
}
decomposedClassesCache.put(baseClass, attributes);
}
return attributes;
}
代码示例来源:origin: intermine/intermine
/**
* Returns the value of a public or protected Field of an Object given the field name
*
* @param o the Object
* @param fieldName the name of the relevant Field
* @return the value of the Field
* @throws IllegalAccessException if the field is inaccessible
*/
public static Object getFieldValue(Object o, String fieldName)
throws IllegalAccessException {
try {
return getGetter(o.getClass(), fieldName).invoke(o, new Object[] {});
} catch (Exception e) {
String type = "";
try {
type = " (a " + getFieldInfo(o.getClass(), fieldName).getGetter().getReturnType()
.getName() + ")";
} catch (Exception e3) {
type = " (available fields are " + getFieldInfos(o.getClass()).keySet() + ")";
}
IllegalAccessException e2 = new IllegalAccessException("Couldn't get field \""
+ Util.decomposeClass(o.getClass()) + "." + fieldName + "\""
+ type);
e2.initCause(e);
throw e2;
}
}
内容来源于网络,如有侵权,请联系作者删除!