org.intermine.metadata.Util.getFriendlyName()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(13.3k)|赞(0)|评价(0)|浏览(158)

本文整理了Java中org.intermine.metadata.Util.getFriendlyName()方法的一些代码示例,展示了Util.getFriendlyName()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.getFriendlyName()方法的具体详情如下:
包路径:org.intermine.metadata.Util
类名称:Util
方法名:getFriendlyName

Util.getFriendlyName介绍

[英]Creates a friendly name for a given class.
[中]为给定类创建友好名称。

代码示例

代码示例来源:origin: intermine/intermine

/**
 * Creates a friendly description of an object - that is, the class and the ID (if it has one).
 *
 * @param o the object to be described
 * @return a String description
 */
public static String getFriendlyDesc(Object o) {
  if (o instanceof InterMineObject) {
    return Util.getFriendlyName(o.getClass()) + ":" + ((InterMineObject) o).getId();
  } else {
    return o.toString();
  }
}

代码示例来源:origin: org.intermine/intermine-objectstore

/**
 * Creates a friendly description of an object - that is, the class and the ID (if it has one).
 *
 * @param o the object to be described
 * @return a String description
 */
public static String getFriendlyDesc(Object o) {
  if (o instanceof InterMineObject) {
    return Util.getFriendlyName(o.getClass()) + ":" + ((InterMineObject) o).getId();
  } else {
    return o.toString();
  }
}

代码示例来源: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

/**
 * 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 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

/**
 * 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

/**
 * Constructs a QueryClass representing the specified set of classes and ObjectStoreBag.
 *
 * @param types the Set of classes
 * @param osb the ObjectStoreBag
 */
public QueryClassBag(Set<Class<?>> types, ObjectStoreBag osb) {
  Class<?> clazz;
  if (types.size() == 1) {
    clazz = types.iterator().next();
  } else {
    clazz = DynamicUtil.composeClass(types);
  }
  if (!InterMineObject.class.isAssignableFrom(clazz)) {
    throw new IllegalArgumentException("Cannot create a QueryClassBag with a class that"
        + " is not a subclass of InterMineObject: " + Util.getFriendlyName(
            clazz));
  }
  @SuppressWarnings("unchecked") Class<? extends InterMineObject> thisType = (Class) clazz;
  this.type = thisType;
  this.osb = osb;
  this.ids = null;
  this.bag = null;
}

代码示例来源:origin: intermine/intermine

/**
 * Constructs a QueryClass representing the specified set of classes and ObjectStoreBag.
 *
 * @param types the Set of classes
 * @param osb the ObjectStoreBag
 */
public QueryClassBag(Set<Class<?>> types, ObjectStoreBag osb) {
  Class<?> clazz;
  if (types.size() == 1) {
    clazz = types.iterator().next();
  } else {
    clazz = DynamicUtil.composeClass(types);
  }
  if (!InterMineObject.class.isAssignableFrom(clazz)) {
    throw new IllegalArgumentException("Cannot create a QueryClassBag with a class that"
        + " is not a subclass of InterMineObject: " + Util.getFriendlyName(
            clazz));
  }
  @SuppressWarnings("unchecked") Class<? extends InterMineObject> thisType = (Class) clazz;
  this.type = thisType;
  this.osb = osb;
  this.ids = null;
  this.bag = null;
}

代码示例来源:origin: org.intermine/intermine-model

/**
 * Adds an element to a public or protected collection of an Object given the field name.
 *
 * @param o the Object
 * @param fieldName the name of the relevant collection
 * @param element the element to add to the collection
 */
public static void addCollectionElement(Object o, String fieldName, Object element) {
  try {
    getAdder(o.getClass(), fieldName).invoke(o, element);
  } catch (Exception e) {
    String type = null;
    try {
      type = getFieldInfo(o.getClass(), fieldName).getElementType().getName();
    } catch (Exception e3) {
      IllegalArgumentException e2 = new IllegalArgumentException("Couldn't add element to"
          + " collection \"" + Util.getFriendlyName(o.getClass()) + "."
          + fieldName + "\"" + " - not an accessible collection");
      e2.initCause(e);
      throw e2;
    }
    IllegalArgumentException e2 = new IllegalArgumentException("Couldn't add element to"
        + " collection \"" + Util.getFriendlyName(o.getClass()) + "."
        + fieldName + "\"" + " (a " + type + ") with \"" + element + "\" (a "
        + element.getClass().getName() + ")");
    e2.initCause(e);
    throw e2;
  }
}

代码示例来源:origin: intermine/intermine

/**
 * Adds an element to a public or protected collection of an Object given the field name.
 *
 * @param o the Object
 * @param fieldName the name of the relevant collection
 * @param element the element to add to the collection
 */
public static void addCollectionElement(Object o, String fieldName, Object element) {
  try {
    getAdder(o.getClass(), fieldName).invoke(o, element);
  } catch (Exception e) {
    String type = null;
    try {
      type = getFieldInfo(o.getClass(), fieldName).getElementType().getName();
    } catch (Exception e3) {
      IllegalArgumentException e2 = new IllegalArgumentException("Couldn't add element to"
          + " collection \"" + Util.getFriendlyName(o.getClass()) + "."
          + fieldName + "\"" + " - not an accessible collection");
      e2.initCause(e);
      throw e2;
    }
    IllegalArgumentException e2 = new IllegalArgumentException("Couldn't add element to"
        + " collection \"" + Util.getFriendlyName(o.getClass()) + "."
        + fieldName + "\"" + " (a " + type + ") with \"" + element + "\" (a "
        + element.getClass().getName() + ")");
    e2.initCause(e);
    throw e2;
  }
}

代码示例来源:origin: org.intermine/intermine-objectstore

/**
 * Constructs a QueryClass representing the specified set of classes and bag of objects.
 *
 * @param types the Set of classes
 * @param bag the Collection of objects
 */
public QueryClassBag(Set<Class<?>> types, Collection<?> bag) {
  Class<?> clazz;
  if (types.size() == 1) {
    clazz = types.iterator().next();
  } else {
    clazz = DynamicUtil.composeClass(types);
  }
  if (!InterMineObject.class.isAssignableFrom(clazz)) {
    throw new IllegalArgumentException("Cannot create a QueryClassBag with a class that"
        + " is not a subclass of InterMineObject: " + Util.getFriendlyName(
            clazz));
  }
  @SuppressWarnings("unchecked") Class<? extends InterMineObject> thisType = (Class) clazz;
  this.type = thisType;
  this.bag = bag;
  ids = convertToIds(bag, this.type);
  this.osb = null;
}

代码示例来源:origin: intermine/intermine

/**
 * Constructs a QueryClass representing the specified set of classes and bag of objects.
 *
 * @param types the Set of classes
 * @param bag the Collection of objects
 */
public QueryClassBag(Set<Class<?>> types, Collection<?> bag) {
  Class<?> clazz;
  if (types.size() == 1) {
    clazz = types.iterator().next();
  } else {
    clazz = DynamicUtil.composeClass(types);
  }
  if (!InterMineObject.class.isAssignableFrom(clazz)) {
    throw new IllegalArgumentException("Cannot create a QueryClassBag with a class that"
        + " is not a subclass of InterMineObject: " + Util.getFriendlyName(
            clazz));
  }
  @SuppressWarnings("unchecked") Class<? extends InterMineObject> thisType = (Class) clazz;
  this.type = thisType;
  this.bag = bag;
  ids = convertToIds(bag, this.type);
  this.osb = null;
}

代码示例来源:origin: org.intermine/intermine-objectstore

/**
 * {@inheritDoc}
 */
@Override
public InterMineObject internalGetObjectById(Integer id,
    Class<? extends InterMineObject> clazz) throws ObjectStoreException {
  InterMineObject retval = super.internalGetObjectById(id, clazz);
  //Exception e = new Exception("internalGetObjectById called for "
  //        + retval.getClass().toString() + " with id " + id);
  //e.fillInStackTrace();
  //java.io.StringWriter sw = new java.io.StringWriter();
  //java.io.PrintWriter pw = new java.io.PrintWriter(sw);
  //e.printStackTrace(pw);
  //pw.flush();
  //LOG.error(sw.toString());
  synchronized (cache) {
    Exception e = new Exception();
    e.fillInStackTrace();
    LOG.warn("Probable inefficiency: internalGetObjectById called "
        + (retval == null ? "" : "to fetch a " + Util.getFriendlyName(retval
            .getClass())) + " with id " + id + ", clazz " + clazz.toString()
        + ", cache size = " + cache.size() + " - maybe you should use"
        + " ObjectStoreFastCollectionsForTranslatorImpl", e);
  }
  internalGetObjectByIdCount++;
  if (internalGetObjectByIdCount % 1000 == 0) {
    LOG.info("internalGetObjectById run " + internalGetObjectByIdCount + " times");
  }
  return retval;
}

代码示例来源:origin: intermine/intermine

/**
 * {@inheritDoc}
 */
@Override
public InterMineObject internalGetObjectById(Integer id,
    Class<? extends InterMineObject> clazz) throws ObjectStoreException {
  InterMineObject retval = super.internalGetObjectById(id, clazz);
  //Exception e = new Exception("internalGetObjectById called for "
  //        + retval.getClass().toString() + " with id " + id);
  //e.fillInStackTrace();
  //java.io.StringWriter sw = new java.io.StringWriter();
  //java.io.PrintWriter pw = new java.io.PrintWriter(sw);
  //e.printStackTrace(pw);
  //pw.flush();
  //LOG.error(sw.toString());
  synchronized (cache) {
    Exception e = new Exception();
    e.fillInStackTrace();
    LOG.warn("Probable inefficiency: internalGetObjectById called "
        + (retval == null ? "" : "to fetch a " + Util.getFriendlyName(retval
            .getClass())) + " with id " + id + ", clazz " + clazz.toString()
        + ", cache size = " + cache.size() + " - maybe you should use"
        + " ObjectStoreFastCollectionsForTranslatorImpl", e);
  }
  internalGetObjectByIdCount++;
  if (internalGetObjectByIdCount % 1000 == 0) {
    LOG.info("internalGetObjectById run " + internalGetObjectByIdCount + " times");
  }
  return retval;
}

代码示例来源:origin: org.intermine/intermine-model

/**
 * Returns the element type of a collection given the field name.
 *
 * @param c the Class
 * @param fieldName the name of the relevant collection
 * @return the class of the field, or null if the field is not found
 * @throws IllegalArgumentException if the field is not a collection
 */
public static Class<? extends FastPathObject> getElementType(Class<?> c, String fieldName) {
  FieldInfo info = getFieldInfo(c, fieldName);
  if (info != null) {
    try {
      return info.getElementType();
    } catch (NullPointerException e) {
      IllegalArgumentException e2 = new IllegalArgumentException("Field "
          + Util.getFriendlyName(c) + "." + fieldName
          + " is not a collection");
      e2.initCause(e);
      throw e2;
    }
  }
  return null;
}

代码示例来源:origin: intermine/intermine

/**
 * Returns the element type of a collection given the field name.
 *
 * @param c the Class
 * @param fieldName the name of the relevant collection
 * @return the class of the field, or null if the field is not found
 * @throws IllegalArgumentException if the field is not a collection
 */
public static Class<? extends FastPathObject> getElementType(Class<?> c, String fieldName) {
  FieldInfo info = getFieldInfo(c, fieldName);
  if (info != null) {
    try {
      return info.getElementType();
    } catch (NullPointerException e) {
      IllegalArgumentException e2 = new IllegalArgumentException("Field "
          + Util.getFriendlyName(c) + "." + fieldName
          + " is not a collection");
      e2.initCause(e);
      throw e2;
    }
  }
  return null;
}

代码示例来源:origin: org.intermine/intermine-objectstore

+ Util.getFriendlyName(o.getClass()) + "." + fieldName + "\""
+ (type == null ? "" : " (a " + type + ")")
+ " to \"" + fieldValue + "\" (a " + fieldValue.getClass().getName() + ")");

代码示例来源:origin: intermine/intermine

+ Util.getFriendlyName(o.getClass()) + "." + fieldName + "\""
+ (type == null ? "" : " (a " + type + ")")
+ " to \"" + fieldValue + "\" (a " + fieldValue.getClass().getName() + ")");

代码示例来源:origin: intermine/intermine

throw new TemplatePopulatorException("The constraint of type " + path.getEndType()
    + " can't be set to object of type "
    + Util.getFriendlyName(obj.getClass())
    + " in template query " + template.getName() + ".");

代码示例来源:origin: org.intermine/intermine-api

throw new TemplatePopulatorException("The constraint of type " + path.getEndType()
    + " can't be set to object of type "
    + Util.getFriendlyName(obj.getClass())
    + " in template query " + template.getName() + ".");

相关文章